当我做git checkout origin/bugfix/NTP-183-datefns
git 显示
Note: checking out 'origin/bugfix/NTP-183-datefns'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b <new-branch-name>
HEAD is now at 6fd089d.
但当我尝试时git checkout bugfix/NTP-183-datefns
Switched to branch 'bugfix/NTP-183-datefns'
Your branch is up-to-date with 'origin/bugfix/NTP-183-datefns'.
这里发生了什么?
origin/<branch-name>
是远程分支引用。它无法修改。
因此,当您签出此引用时,git 无法将您移至此分支,但会将您移至该分支引用的提交。那么你就处于一个分离头状态,这意味着您不在分支上,而是直接在提交上(其含义在命令的输出中进行了解释)。
<branch-name>
只是一个本地分支,因此您可以在其中工作。
因此,当您签出此参考资料时,git 会将您移至分支。
有一个小提示:如果本地分支<branch-name>
不存在,但所有远程分支上都存在一个同名的远程分支,git 会自动创建本地分支,跟踪远程分支并签出它(在这种情况下)git checkout <branch-name>
相当于git checkout --track -b <branch-name> any_remote/<branch-name>
)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)