2

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.

StaticCrazee
  • 167
  • 1
  • 11

1 Answers1

6

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
Sazzadur Rahaman
  • 6,938
  • 1
  • 30
  • 52
  • But wouldn't the parents of 796ddb0 be 4c9749e and 1a56a81, with 0c5975a being a branch of 1a56a81. I feel like I'm missing something here. – StaticCrazee Jul 19 '18 at 22:44
  • No. The parents of 796ddb0 are 0c5975a and 4c9749e. You can think of it like this, when you created a branch (heading-update) from 1a56a81, at that moment you have two children of 1a56a81. They are 0c5975a and 4c9749e. After merging `heading-update` back, these two child have one common child (796ddb0). Now if you look back from 796ddb0, 796ddb0 will see two parents. Since 796ddb0 is the parent of db7e87a, db7e87a will see two grand-parents. – Sazzadur Rahaman Jul 19 '18 at 22:55
  • TLDR; When you are on 796ddb0, you will see both the changes from 0c5975a and 4c9749e. This makes 0c5975a and 4c9749e the parents of 796ddb0. – Sazzadur Rahaman Jul 19 '18 at 23:06
  • Oh okay! Thanks for the thorough explanation! – StaticCrazee Jul 20 '18 at 06:35