Having two commits SHA1, how do I get which went first without manually analyzing the git log?
Note that I am not trying to find which one is the ancestor of the another, I want to know which one was pushed first.
I want to get it by it's chronological order in the git history, not by the commit date. Any method is welcome but a straight forward way is preferred (I am using it directly on my terminal emulator, not on a script).
I tried using git merge-base
as @wRAR suggested.
First off, there is a drawback: git merge-base --is-ancestor
doesn't give me output. It exits with 0 or 1 without outputing anything to stdout. Its ok when scripting, but when manually using it directly on my terminal I have to check the exit status in a extra step afterwards (echo $?
on bash, $LASTEXITCODE
on PowerShell). Not a deal breaker, but generates a little hassle.
But, anyway, it didn't work.
Works in the following scenario:
> git log --oneline --graph
| * <SHA1 D> Fourth commit.
| * <SHA1 C> Third commit.
| * <SHA1 B> Second commit.
| * <SHA1 A> First commit.
> git merge-base --is-ancestor <SHA1 B> <SHA1 C>
> echo $?
0
> git merge-base --is-ancestor <SHA1 C> <SHA1 B>
> echo $?
1
But not in this one (doesn't do what I intend):
> git log --oneline --graph
* <SHA1 D> Merged work.
|\
| * <SHA1 C> Paul's first commit.
* | <SHA1 B> John's second commit.
|/
* <SHA1 A> John's first commit.
> git merge-base --is-ancestor <SHA1 B> <SHA1 C>
> echo $?
1
> git merge-base --is-ancestor <SHA1 C> <SHA1 B>
1