Git:HEAD已经消失,想要将它合并到master中 [英] Git: HEAD has disappeared, want to merge it into master

查看:212
本文介绍了Git:HEAD已经消失,想要将它合并到master中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

reflog vs GITK http://siteroller.net/archive/images/Forums / headless%20GIT.png



最上面的图片是git reflog的输出。

GITK的底部是GITK当我查看所有分支历史记录时,GUI(msysgit)显示了我。



最后几个提交不显示在GIT GUI上。




  • 为什么它们不显示在GITK上(至少作为一个分支或什么)?
  • 如何将它们合并到master? li>
  • 当我检出标签0.42时,我收集了这件事。为什么和主人不一样? (我标记了最新状态的主人)

  • 当我点击推送时,为什么远程仓库声称是最新的..不应该尝试将这些提交更新为无论他们在哪个分支?



第一个问题很重要 - 我想开始理解GIT的想法。在这一点上,它比逻辑更像甲骨文。



如果它看到较早的历史有所不同,该项目是一个[非常强大] JS颜色选择器,可以<一个href =http://github.com/siteroller/ColorRoller-MooTools-Color-Picker =noreferrer>在此处查看。

就是这样:你不在任何分支上,但目前正在处理 分离的头部


从版本1.5.0开始,上述命令将您的 HEAD 从当前分支中分离出来,并直接指向标记所指定的提交。


如果您执行 gitk --all



解决这个问题的一种方法(如果你已经犯下了一切)

  $ git log -1 
#注意最新提交的SHA-1
$ git checkout master
#将你的分支头重置到你之前分离的提交
$ git reset - 硬< commit-id>

另一种方法是将你的工作合并到恰好在标签处的当前主HEAD中:

  $ git checkout -m 0.42 

,但是这会丢失您在提交的头文件中提交的历史记录。





我收集这件事发生在我检出标签0.42时。为什么和主人不一样? (我已经标记了最新状态的主人)


不,它与主人不一样。正如 Jefromi 在评论中指出的那样,分支机构可以移动(或被重命名,或删除,或......) >
master 指的是与'0.42'标签相同的提交,但情况并非总是如此。

With一个标签的签出,你不签出一个分支,因此'分离HEAD'状态。






注意:as在这个SO答案中提到, @ {1} 您看到的表示法是 $(git symbolic-ref HEAD)@ {1} ,即它使用reflog表示当前这里分开)分支,而不是HEAD reflog。

reflog vs GITK http://siteroller.net/archive/images/Forums/headless%20GIT.png

The top image is the output of: git reflog.
The bottom is what GITK in GIT GUI (msysgit) shows me when I look at all branch history.

The last few commits do not show on GIT GUI.

  • Why do they not show on GITK (at least as a branch or something)?
  • How do I merge them into master?
  • I gather this happened when I checked out tag 0.42. Why is that not the same as master? (I had tagged the master in its latest state)
  • When I click push, why does the remote repo claim to be up to date.. shouldn't it try to update these commits into whatever branch they are in?

The first of the questions is important - I would like to begin to understand what GIT is thinking. It's more oracle than logic at this point.

If it makes a difference to see the earlier history, the project is a [pretty powerful] JS color picker that can be viewed here in its entirety.

解决方案

why to update these commits into whatever branch they are in?

That's just it: you are not on any branch but currently working on a detached head:

starting from version 1.5.0, the above command detaches your HEAD from the current branch and directly points at the commit named by the tag.

You might see it if you do a gitk --all

One way to fix it (if you have committed everything)

$ git log -1
# note the SHA-1 of latest commit
$ git checkout master
# reset your branch head to your previously detached commit
$ git reset --hard <commit-id>

Another way would be to merge your work into the current master HEAD which happens to be at the tag:

 $ git checkout -m 0.42

but that looses the history of your commits made on a detached HEAD.


I gather this happened when I checked out tag 0.42. Why is that not the same as master? (I had tagged the master in its latest state)

No it is not the same than master. As Jefromi points out in the comments, branch can move (or be renamed, or deleted, or...)
master was referring to the same commit than the '0.42' tag, but that won't be always the case.
With a checkout of a tag, you do not checkout a branch, hence the 'detached HEAD' state.


Note: as mentioned in this SO answer, the @{1} notation you see is $(git symbolic-ref HEAD)@{1}, i.e. it is uses reflog for current (here detached) branch, not HEAD reflog.

这篇关于Git:HEAD已经消失,想要将它合并到master中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆