在子目录工作中如何查看old_branch *?
我是Git的新手,最近对下面的代码感到困惑。我的问题是,
- 为什么
git branch new_branch
将复制当前Release_branch
? - 结帐新分支后,为什么我们可以输入子目录,然后重新检查一个旧分支以带上旧脚本?
- 为什么最后一个结帐行(对于旧分支)只能恢复此子目录中的文件,而不是将所有脚本或切换到旧分支?
# Say pwd is /home/ab/
git checkout -f $RELEASE_BRANCH
git branch $NEW_REPAIR_BRANCH
git checkout $NEW_REPAIR_BRANCH
cd /home/ab/cd/ef/
rm -r *
git checkout $OLD_REPAIR_BRANCH *
有人可以帮助我解释逻辑吗?非常感谢!顺便说一句,我相信他们也应该能够简化!
I am new to git and recently get confused about the code below. My question are,
- Why
git branch new_branch
will copy the currentrelease_branch
? - After checkout the new branch, why we could enter a sub directory and just re-checkout an old branch to bring in the old script?
- Why the last checkout line (for old branch) will only restore the files in this subdirectory instead of bringing all scripts or switching to the old branch?
# Say pwd is /home/ab/
git checkout -f $RELEASE_BRANCH
git branch $NEW_REPAIR_BRANCH
git checkout $NEW_REPAIR_BRANCH
cd /home/ab/cd/ef/
rm -r *
git checkout $OLD_REPAIR_BRANCH *
Is there anyone could help me explain the logic? Much appreciate! Btw, I believe they should be able to be simplified as well!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
git branch new_branch
git branch new_branch head
是简短的。它从当前头创建new_branch
。如果head
指向Release_branch
,则相当于git branch new_branch Release_branch
。git Checkout $ old_repair_branch
意思是“结帐$ old_repair_branch”。但是git Checkout $ old_repair_branch *
完全不同。它根本不会切换分支。*
是指当前文件夹下的所有文件和目录。名称以点开头的文件和目录被排除在外,例如.git
和.gitignore
。git Checkout $ old_repair_branch *
在old_repair_branch
中更新了其版本的文件。想象一下,它创建了一个文件,其内容记录在old_repair_branch
中。由于*
仅引用当前目录下的条目,因此其父目录和兄弟姐妹目录中的文件不受影响。git branch new_branch
is short forgit branch new_branch HEAD
. It createsnew_branch
from the current HEAD. IfHEAD
points torelease_branch
, then it's equivalent togit branch new_branch release_branch
.git checkout $OLD_REPAIR_BRANCH
means "to checkout $OLD_REPAIR_BRANCH". Butgit checkout $OLD_REPAIR_BRANCH *
is quite different. It does not switch the branch at all.*
means all files and directories under the current folder. The files and directories whose names start with a dot are excluded, like.git
and.gitignore
.git checkout $OLD_REPAIR_BRANCH *
updates the files with their versions inOLD_REPAIR_BRANCH
. Imagine that it creates a file with its content recorded inOLD_REPAIR_BRANCH
. As*
refers to the entries under the current directory only, the files in its parent directories and sibling directories are not affected.可以使用新
git> git switch
command command command command command commit( a href =“ https://git-scm.com/docs/git-switch” rel =“ nofollow noreferrer”> man page ),以及git Restore
(用于基于文件的操作: Man Page )。这样,您清楚地将分支开关与文件还原步骤区分开。
并且您避免'
*
',这取决于要解释和扩展的基础外壳。Anything done with git checkout/git branch could be done with the new
git switch
command (man page), as well asgit restore
(for file-based operations: man page).That way, you clearly distinguish the branch switches from the files restore steps.
And you avoid '
*
', which depends on the underlying shell to be interpreted and expanded.