Reputation: 297
I was looking through a Git course (on relative commits) when I encountered the following:
* 9ec05ca (HEAD -> master) Revert "Set page heading to "Quests & Crusades""
* db7e87a Set page heading to "Quests & Crusades"
* 796ddb0 Merge branch 'heading-update'
|\
| * 4c9749e (heading-update) Set page heading to "Crusade"
* | 0c5975a Set page heading to "Quest"
|/
* 1a56a81 Merge branch 'sidebar'
|\
| * f69811c (sidebar) Update sidebar with favorite movie
| * e6c65a6 Add new sidebar content
* | e014d91 (footer) Add links to social media
* | 209752a Improve site heading for SEO
* | 3772ab1 Set background color for page
|/
* 5bfe5e7 Add starting HTML structure
* 6fa5f34 Add .gitignore file
* a879849 Add header to blog
* 94de470 Initial commit
Referring to commits relative to HEAD (SHA 9ec05ca), the instructor wrote the following:
HEAD^ is the db7e87a commit
HEAD~1 is also the db7e87a commit
HEAD^^ is the 796ddb0 commit
HEAD~2 is also the 796ddb0 commit
HEAD^^^ is the 0c5975a commit
HEAD~3 is also the 0c5975a commit
HEAD^^^2 is the 4c9749e commit (this is the grandparent's (HEAD^^) second parent (^2))
My confusion lies with HEAD's great-grandparent (HEAD^^^) which I think should be 4c9749e or 1a56a81 (parents of the merge 796ddb0). I've looked around everywhere (including What's the difference between HEAD^ and HEAD~ in Git?). But it only made the instructor's answer more confusing.
Upvotes: 2
Views: 3059
Reputation: 7116
Confusion about the parents of the merge 796ddb0 (you think it should be 4c9749e or 1a56a81)
No. When you are merging the branch heading-update
back, by this time the original head moved from 1a56a81 to 0c5975a. So the merge commit is actually merging two current heads (0c5975a and 4c9749e). As a result the parents of 796ddb0 are 0c5975a and 4c9749e.
Now, if you are convinced, then we can visualize the graph as following (I just replaced stars (*
) with commit ids),
9ec05ca
|
db7e87a
|
796ddb0
/\
/ \
0c5975a 4c9749e
\ /
\ /
1a56a81
The above graph leads to the following conclusion.
HEAD^^^ --> ((HEAD^1)^1)^1
--> ((db7e87a)^1)^1
--> (796ddb0)^1
--> 0c5975a
Upvotes: 6