In a Udacity lesson covering relative commit references, it says:
^ indicates the parent commit, ~ indicates the first parent commit
The main difference between the ^ and the ~ is when a commit is created from a merge. A merge commit has two parents. With a merge commit, the ^ reference is used to indicate the first parent of the commit while ^2 indicates the second parent. The first parent is the branch you were on when you ran git merge while the second parent is the branch that was merged in.
According to the lesson, based on the following output of git log --graph --oneline
, the commit with SHA f69811c
is HEAD~4^2
relative to the (topmost, with the head pointer) commit 9ec05ca
.
So HEAD~4 on its own means the first parent, while ^2 means it's also the second parent? Don't these things contradict each other? Any clarification appreciated.
~n
says chase a first-parent link that many times, default 1,^n
says chase the nth-parent link, default 1. – Cresida