【问题标题】:Why is my local Git branch detached? [duplicate]为什么我的本地 Git 分支是分离的? [复制]
【发布时间】:2015-03-19 16:18:44
【问题描述】:

我的本​​地 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

为什么我的分支是分离的?我做错了什么?

【问题讨论】:

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


【解决方案1】:

你需要

git checkout bugfix/bug-on-user

不是

git checkout origin/bugfix/bug-on-user

否则它不会是本地分支...嗯,实际上它将是一个本地分支,但不是你的意思,它将是一个 remote-tracking-branch,即一个你永远不应该直接使用的分支,但它在从远程存储库中提取/获取数据时使用。

【讨论】:

  • git checkout bugfix/bug-on-user 不起作用,因为 bugfix/bug-on-user 不存在。你的意思是git checkout -b bugfix/bug-on-user?此外,origin/bugfix/bug-on-user 是本地的,因为它存在于本地 repo 中;它只是一种特殊类型的本地分支(我喜欢称它们为远程跟踪分支,以区别于远程分支),它只是为了反映一个远程分支,即位于远程仓库中的分支。
  • 实际上git checkout bugfix/bug-on-user 大部分时间都在工作,git 似乎足够聪明,可以确定它应该跟踪远程分支。
  • 你是对的。我没有注意到。
猜你喜欢
  • 2018-05-20
  • 1970-01-01
  • 2014-11-13
  • 2019-09-18
  • 1970-01-01
  • 1970-01-01
  • 2018-02-15
  • 1970-01-01
  • 2019-10-30
相关资源
最近更新 更多