为什么我的本地Git分支脱离了?

时间:2015-03-19 16:18:45

标签: git git-branch git-detached-head

我当地的Git分支机构发生了什么?以下是我运行的命令序列:

$ git fetch --all
$ git branch
* feature/myfeature1
  master
  branch-dev
$ git branch -a
* feature/myfeature1
  master
  branch-dev
  remotes/origin/bugfix/bug-on-user
  remotes/origin/feature/myfeature2
$ git checkout origin/bugfix/bug-on-user
M       com.soc.data/.settings/org.eclipse.jdt.core.prefs
M       com.soc.data/META-INF/MANIFEST.MF
Note: checking out 'origin/bugfix/bug-on-user'.

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 d467d95... ...

$git branch
* (detached from origin/bugfix/bug-on-user)
   feature/myfeature1
   master
   branch-dev

为什么我的分店脱离了?我做错了什么?

1 个答案:

答案 0 :(得分:2)

你需要

git checkout bugfix/bug-on-user

不是

git checkout origin/bugfix/bug-on-user

否则它不会是本地分支......好吧,实际上它将是一个本地分支,但不是你的意思,它将是一个远程跟踪分支,这是您永远不应该直接处理的分支,但在从远程存储库中提取/获取数据时使用该分支。