Search code examples
gitgit-log

Meaning of git log --oneline --graph output


I'm learning about relative commit references and trying to understand the following git log --oneline --graph output provided in a lesson.

git graph

In the lesson it says that given HEAD points to the 9ec05ca commit, HEAD^^^ (meaning the great-grandparent commit) is the 0c5975a commit. But it seems to me 4c9749e should be the great grandparent, if each SHA is a direct descendant of the one below it. Any clarification appreciated.


Solution

  • Commit can have more than one parent. ^ 1 means first parent. ^2 means second parent and so on. Just ^ defaults to ^1 which is first parent.

    Similarly ~ give access to traverse up for an ancestor. For example if you want 3 generation up ~3. If you want 7th last commit in same branch favouring first parent while traversing.

    Any merge will have two parents with merge to branch becoming first parent. Merge from branch becoming second parent.