git - 切换到远程分支获取分离头

标签 git git-detached-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 意味着您的 HEAD 指向不是提交链中最新的提交。

在此示例中,提交 #4 是最新的,而 HEAD 指向提交 #2。

enter image description here

关于git - 切换到远程分支获取分离头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35301931/

相关文章:

Git子模块分离头状态

git - 恢复由于分离头而意外丢失的提交

git - rebasing 分支,有自己的分支

git - 为什么在检查最近的提交后我有一个分离的 HEAD?

git - git 中有没有办法将单个文件中的更改拆分为两个提交?

git - 在 Git 中跨多个分支区分单个文件

git - 用标签固定分离的头

git - 有没有办法撤消分离的 HEAD 状态,而不撤消我在分离的 HEAD 状态下所做的工作?

git - libgit2sharp 中可以进行 merge 吗?

git - 从 TFS 迁移到 Git