相对提交参考

时间:2018-07-19 22:08:30

标签: git github version-control

当我遇到以下情况时,我正在浏览Git课程(有关相对提交):

* 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

参考相对于HEAD(SHA 9ec05ca )的提交,讲师编写了以下内容:

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))

我的困惑在于 HEAD 的曾祖父母( HEAD ^^^ ),我认为这应该是 4c9749e 1a56a81 (合并 796ddb0 的父母)。我到处都是(包括What's the difference between HEAD^ and HEAD~ in Git?)。但这只会使教师的回答更加混乱。

1 个答案:

答案 0 :(得分:3)

  

关于合并796ddb0的父母的困惑(您认为应该是4c9749e或1a56a81)

不。当您将分支heading-update合并回去时,此时原始磁头已从1a56a81移至0c5975a。因此,合并提交实际上是合并两个当前头(0c5975a和4c9749e)。结果,796ddb0的父代是0c5975a和4c9749e。

现在,如果您确信,那么我们可以将图形可视化如下(我刚刚用提交ID替换了星号(*),

              9ec05ca
                 |
              db7e87a
                 |
              796ddb0
                /\
               /  \
         0c5975a  4c9749e
              \    /
               \  /
              1a56a81

上图得出以下结论。

HEAD^^^ --> ((HEAD^1)^1)^1
        --> ((db7e87a)^1)^1
        --> (796ddb0)^1
        --> 0c5975a