Why does git think HEAD is the first commit from 17 years ago?

落花浮王杯 提交于 2019-12-24 05:56:12

问题


I'm trying to gather up the list of commits in the range [NOW, THEN], where NOW is HEAD and [THEN] is 8af39377, and its about 120 commits ago.

When I run:

>  git log 8af39377289feba1876b3252b6d23 HEAD --oneline | cut -d " " -f 1 > commits.txt

and then look at commits.txt, its 2300 lines long and it shows the top entry as 8af39377 (the THEN) and the bottom entry as a3b6ece (the first commit from 2002).

Why does Git think HEAD is the first commit to the repository?


回答1:


Your syntax is wrong. If you want the range between 8af39 and HEAD then you need 8af39..HEAD

As for WHY it's showing 17 years ago, if you just specify a single revision, it will find all the commits REACHABLE by that commit. Since all commits have backwards pointers all the way to the root, you're finding the root commit.

Revision Specification See the section on specifying a range.




回答2:


git log 8af39377289feba1876b3252b6d23 HEAD --oneline

That says "give me the entire history of those two commits, sorted in date order constrained by ancestry".

You want

the list of commits in the range [NOW, THEN], where NOW is HEAD and [THEN] is 8af39377, and its about 120 commits ago

but your log output contradicts you on which is which: git log shows its output most-recent first, constrained by ancestry, and

it shows the top entry as 8af39377.

so you're wrong about your commit order. If you hadn't silenced the default output it would have shown you the commit dates explicitly as well, so you'd see whether it's a date or ancestry issue.

Regardless which it is,

git log --oneline HEAD..8af39377

will show you the list.

It might be worth adding --graph --decorate.



来源:https://stackoverflow.com/questions/41688733/why-does-git-think-head-is-the-first-commit-from-17-years-ago

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!