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/

相关文章:

android - 如何将项目从 android studio 推送到现有存储库中的特定 github 文件夹?

php - 哎呀,看起来像出事了。尝试在内置服务器上运行时 Laravel 5 出现错误

python - 使用 pbr 时如何将 git repo 包含为依赖项

ruby-on-rails - Omniauth:使用 Github 登录(404 访问 token )

version-control - SCM URL 相对于 POM 中的父 SCM URL

javascript - 静态资源版本控制管理方法 : javascript/css/html files etc

Eclipse 4.6.1 JGit/EGit 升级后验证时间更长

git - 在 GitHub 组织的代码中搜索部分单词

github - 如何在Jekyll's Liquid模板中比较字符串大小/长度?

git - 将本地分支从另一个本身经常重新定位的分支中重新定位是不是很糟糕?