为什么git HEAD~ [N]只引用pull请求?

时间:2017-08-17 11:28:55

标签: git github

我看过的每个地方都说,要获得之前的提交,请执行

git checkout HEAD~1

在git存储库中。但是当我这样做时,会跳过许多提交。有问题的存储库是Google upb library

编辑:

这些是通过运行

获得的引用存储库中的最后10个提交
git log --pretty=oneline

ae30b4a816a57a8101ce187245edc3050d515c06 Merge pull request #90 from haberman/gencode3
72c333eb037da6fe63358efe9c6dc29547b0ab49 Fixed amalgamated build.
058a17f6a6c2487fd674511d5409497a03e83758 Fix amalgamated build.
98f513fb8fa5e3360baeb59c37636ca71d562490 Fixed 32-bit build and added generated files.
6b8767422154008eed98d0df42e36758d38877a4 Address review comments and fix compile warnings.
806ffc1d2053f1c02167c7965b39abc997d12ad6 Responded to PR comments.
15308afff2d0d288b73c1b4278bd28f926ce02b8 Fixes for oneof conformance tests.
b697882fb272c2f3408f5c821a88aaf3e3db6f52 Fixed varint length when buffer is reallocated.
be9094d91a2da777002a0f713306ac1bb74a6ac5 New encode/decode: most (171 / 192) conformance tests pass.
d5167fff744167eca45df65b5b935525778e2886 Merge pull request #88 from google/gencode2

亲自看看。运行git checkout HEAD~1会产生以下消息

Previous HEAD position was ae30b4a... Merge pull request #90 from haberman/gencode3
HEAD is now at d5167ff... Merge pull request #88 from google/gencode2

所以HEAD已经移回了9次提交,而不是1次。

再次运行git log以获取相对于HEAD的提交历史记录(位于d5167ff)。

git log --pretty=oneline

d5167fff744167eca45df65b5b935525778e2886 Merge pull request #88 from google/gencode2
6eb489a30ab0bc4e859944650f13db7a706e27da Merge branch 'master' into gencode2
0af928564ef4bb1ad3aa7cef26929bab7836f876 Merge pull request #89 from google/stringview
1278ff899409025692d6915421f1af1c99dc837e Responded to PR comments.
c0a660f474384e0e3c7d4dd75c9b3e6b32daca9f Added upb_stringview, the string representation for upb_msg.

再次运行git checkout HEAD~1会产生

Previous HEAD position was d5167ff... Merge pull request #88 from google/gencode2
HEAD is now at 0af9285... Merge pull request #89 from google/stringview

显然已经跳过了几个提交。

1 个答案:

答案 0 :(得分:1)

git .... HEAD~n走回了曾祖父母。参考文档

  

修订参数的后缀〜表示提交对象,它是指定提交对象的第三代祖父,仅跟随第一个父对象。即~3相当于^^^,相当于^ 1 ^ 1 ^ 1。请参阅下文,了解此表单的使用说明。

如果你现在有一个合并提交,你显然已经在你的HEAD位置上走回n代可能会导致时间线跳转到该合并的下一个祖父母。在你的情况下,它是0af9285