<分区>
这是我所有分支的列表:
$ git branch -a
* temp
remotes/heroku/master
remotes/origin/dev
remotes/origin/master
当我键入 git checkout remotes/origin/master
以切换到我的原始 master
分支时,Git 切换到分离的 HEAD 状态。为什么?
<分区>
这是我所有分支的列表:
$ git branch -a
* temp
remotes/heroku/master
remotes/origin/dev
remotes/origin/master
当我键入 git checkout remotes/origin/master
以切换到我的原始 master
分支时,Git 切换到分离的 HEAD 状态。为什么?
最佳答案
这是正确的行为,因为您已经检查了远程 分支。
如果你想查看 master 并对其进行处理,你应该现在就这样做:
# checkout remote branch as local branch
# this will look up the branch name locally and if it does not find it it
#will checkout your remote branch with this name.
git checkout master
当你 checkout 远程分支时,你只是指向你的 HEAD到该分支的最新提交。如果你想在它上面工作,你必须将它 checkout 为没有 remote/<branch>
的本地分支。 强>。这将自动 checkout 并创建具有给定名称的本地分支。
如果您想了解更多关于 HEAD 的信息阅读所有相关信息 here .
分离的 HEAD 意味着您的 HEAD 指向不是提交链中最新的提交。
在此示例中,提交 #4 是最新的,而 HEAD 指向提交 #2。
关于git - 切换到远程分支获取分离头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35301931/