1

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?

Community
  • 1
  • 1
jww
  • 97,681
  • 90
  • 411
  • 885

2 Answers2

3

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.

jbu
  • 15,831
  • 29
  • 82
  • 105
  • 1
    I guess its no surprise... I followed the cited answer's instructions of ` `, which produces the output above. Your answer produces no output. And no surprise that Git does not produce a warning or error. What a miserable tool... – jww Jan 17 '17 at 03:58
  • Can you verify a few things for me. 1) You are indeed using 2 dots instead of 3? 2) Your HEAD is indeed after 8af39? Just want to make sure that the order of commits is correct. 3) 8af39 is indeed reachable by HEAD / your current branch. Make sure you just use the `git log blah blah` command to eliminate `cut` as a source of errors. – jbu Jan 17 '17 at 04:06
  • There is one extra detail that I have to mention. This works if HEAD is not a merge commit. If HEAD is a merge commit, then the result of the command I gave you will also include commits that may not be reachable by 8af39. It could list some extra commits more recent than the merge-base. – jbu Jan 17 '17 at 04:46
1
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.

jthill
  • 55,082
  • 5
  • 77
  • 137
  • think this is backwards, isnt it? 8af39377 is 120 commits before HEAD. HEAD..8af39377 is the commits reachable from 8af39377 with the commits reachable from HEAD excluded. So you're excluding the things after 8af39377 here. – jbu Jan 17 '17 at 04:51
  • As I said, your log output contradicts you on this: `8af39377` shows up first, which means it isn't an ancestor of `HEAD` (else `HEAD` would have come first) and has a more recent date (else `HEAD` would have come first). By the way, your `cut` just gets you the commit ids, if listing revs is all you want, why not use `git rev-list` (`git log`'s -- as well as a whole heck of a lot of other revision-walking commands') more laser-focused sire) or `git log --pretty=%H`? – jthill Jan 17 '17 at 04:56
  • You werent speaking to op. Though im wondering what you think git log commit1 commit2 does. Actually the docs seem a bit fuzzy on what should happen but i think the commit1 is being treated as the commit and commit two is being treated as a path since it is a treeish and will resolve to the root tree object – jbu Jan 17 '17 at 05:14
  • Contd: in which case 8af39 should appear first – jbu Jan 17 '17 at 05:16