git - 相对提交引用

标签 git github version-control

当我遇到以下内容时,我正在浏览 Git 类(class)(关于相对提交):

* 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 的曾祖 parent (HEAD^^^) 感到困惑,我认为它应该是 4c9749e 1a56a81( merge 796ddb0 的父级)。我环顾四周(包括 What's the difference between HEAD^ and HEAD~ in Git? )。但这只会让导师的回答更加困惑。

最佳答案

Confusion about the parents of the merge 796ddb0 (you think it should be 4c9749e or 1a56a81)

没有。当您将分支 heading-update merge 回来时,此时原始头部从 1a56a81 移动到 0c5975a。所以 merge 提交实际上是 merge 两个当前头(0c5975a 和 4c9749e)。结果796ddb0的双亲是0c5975a和4c9749e。

现在,如果你相信了,那么我们可以将图表可视化如下(我只是用提交 ID 替换了星号 (*)),

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

从上图可以得出以下结论。

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

关于git - 相对提交引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51432398/

相关文章:

svn - 我如何使用 git-svn 只获取/克隆几个分支?

ruby-on-rails - sprockets rails 和 sprockets gem 有什么区别?

windows - 如何在 Windows 上更改远程/目标存储库 URL?

git: checkout 一个标签,修改一些东西,然后再次标记它

github - 如果您不是贡献者/所有者,如何在 GitHub 中为问题贴上标签?

git - git 和 github 的工作流程最佳实践?

version-control - 你应该避免编辑哪些 symfony 自动生成的文件?

git - 'git pull' 不更新来自远程分支的更改

git - 如何取消提交最后的 n 次提交?

git - pull 本地仓库时获取 Remote