Question

git log shows:

commit 9914d84b8dc8fa21826dbaefe753d2a8a2efa09c (HEAD)
Date:   Mon May 12

    A

commit 24179a67763900ea42dd8124b2e383ac880b2dd7 (HEAD~1)
Merge: fe3a994 df9ad68
Date:   Mon May 12

    (B) Merge branch 'master' of this repository

commit fe3a994d7c1a8b174511a86dd7503427caa45bd7 (HEAD~2)
Date:   Mon May 12

    C

commit df9ad689ba70f7bc658d9c68d95dd3ebdd1ae7ec (HEAD~3)
Date:   Mon May 12

    D

commit 2b403d17449abbabee4c0ecf26199382bef974c7 (HEAD~4)
Date:   Mon May 12

   E

commit b394dba1faf79d18129c172843115ae66a964e76 (HEAD~5)
Date:   Sun May 11

    F

git show HEAD, git show HEAD~1 and git show HEAD~2 show the correct commits (A, B and C).

I naturally thought git show HEAD~3 would show commit D, however it does not, and shows commit E instead.

How to select the D commit without using SHA?

Was it helpful?

Solution

Your history is not linear, because 24179a67763900ea42dd8124b2e383ac880b2dd7 (aka HEAD~1) has two parents. According to gitrevisions HEAD~3 means HEAD^^^. That means apply trice the operation "get the first parent". df9ad689ba70f7bc658d9c68d95dd3ebdd1ae7ec is not HEAD~3. It is HEAD^1^2 (second parent of the first parent of HEAD).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top