reflog vs GITK http://siteroller.net/archive/images/Forums/headless%20GIT.png
上图是 git reflog 的输出。
底部是 GIT GUI (msysgit) 中的 GITK 在我查看所有分支历史记录时向我显示的内容。
最后几次提交不会显示在 GIT GUI 上。
- 为什么它们不显示在 GITK 上(至少作为分支或其他)?
- 如何将它们 merge 到 master 中?
- 我发现这发生在我查看标签 0.42 时。为什么和master不一样? (我已经标记了最新状态的主人)
- 当我点击推送时,为什么远程仓库声称是最新的..它不应该尝试将这些提交更新到它们所在的任何分支吗?
第一个问题很重要——我想开始了解 GIT 在想什么。在这一点上,它更像神谕而不是逻辑。
如果查看早期历史有所不同,该项目是一个[非常强大] JS 颜色选择器,可以是 viewed here完整的。
why to update these commits into whatever branch they are in?
就是这样:您不在任何分支机构,但当前正在处理 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.
如果你执行 gitk --all
你可能会看到它
修复它的一种方法(如果您已提交所有内容)
$ 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>
另一种方法是将您的工作 merge 到当前主 HEAD 中,该 HEAD 恰好位于标签处:
$ git checkout -m 0.42
但这会丢失您在分离的 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)
不,它与 master 不同。作为Jefromi在评论中指出,分支可以移动(或重命名,或删除,或...)
master
指的是与“0.42”标签相同的提交,但情况并非总是如此。
通过 checkout 标签,您不会 checkout 分支,因此处于“分离的 HEAD”状态。
注:如this SO answer所述,您看到的 @{1}
表示法是 $(git symbolic-ref HEAD)@{1}
,即它对当前(这里是分离的)分支使用 reflog,不是 HEAD 重新登录。