切换到远程分支头断开 [英] Switch to a remote branch getting detached head
问题描述
这是我所有分支机构的列表:
Here is a list of all my branches:
$ git branch -a
* temp
remotes/heroku/master
remotes/origin/dev
remotes/origin/master
当我键入git checkout remotes/origin/master
切换到我的原点master
分支时,Git切换到分离的HEAD状态.为什么?
When I type git checkout remotes/origin/master
to switch to my origin master
branch, Git switches to a detached HEAD state. Why?
推荐答案
这是正确的行为,因为您已签出远程分支.
This is the right behavior since you have checked out the remote branch.
如果您希望检出master并进行操作,请立即执行以下操作:
If you wish to check out master and work on it you should do this now:
# 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
签出远程分支时,您只需指向 HEAD 到该分支的最新提交.如果您希望对其进行处理,则必须将其检出为本地分支,而不使用 remote/<branch>
.这将自动签出并使用给定名称创建本地分支.
When you checkout remote branch you are simply pointing your HEAD to the latest commit from this branch. If you wish to work on it you have to check it out as local branch without the remote/<branch>
. This will automatically checkout and create local branch with the given name.
If you wish to learn more about the HEAD read all about it here.
分离的HEAD表示您的HEAD指向的提交不是提交链中的最新内容.
A detached HEAD mean that your HEAD point to a commit which is not the lates in the commit chain.
在此示例中,提交#4是最新的,而HEAD指向提交#2.
In this sample commit #4 is the latest while the HEAD is pointing to commit #2.
这篇关于切换到远程分支头断开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!