Git中HEAD ^和HEAD〜有什么区别? [英] What's the difference between HEAD^ and HEAD~ in Git?

查看:177
本文介绍了Git中HEAD ^和HEAD〜有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在Git中指定一个祖先提交对象时,我很困惑 HEAD ^ HEAD〜 b
$ b

两者都有一个编号版本,如 HEAD ^ 3 HEAD〜2



它们与我看起来非常相似或相同,但是在代字号和插入符号之间是否有区别?

解决方案

HEAD ^ 表示当前分支尖端的第一个父项。



请记住,git提交可以有多个父代。 HEAD ^ HEAD ^ 1 的缩写,您还可以在 HEAD ^ 2 等等。



你可以得到任何提交的父母,而不仅仅是 HEAD 。您也可以通过几代人回溯:例如, master〜2 表示主分支尖端的祖父母,在不明确的情况下赞成第一父母。这些说明符可以任意链接
eg topic〜3 ^ 2



有关完整的详细信息,请参阅<$ c中的指定修订

为了直观地表达这个想法,我们引用部分文档: git rev-parse / p>


以下是Jon Loeliger的插图。提交节点B和C都是提交节点A的父节点。父提交按从左到右的顺序排列。



  GHIJ 
\ / \ /
DEF
\ | / \
\ | / |
\ | / |
BC
\ /
\ /
A

A = = A ^ 0
B = A ^ = A ^ 1 = A〜1
C = A ^ 2 = A ^ 2
D = A ^^ = A ^ 1 ^ 1 = A〜2
E = B ^ 2 = A ^^ 2
F = B ^ 3 = A ^^ 3
G = A ^^^ = A ^ 1 ^ 1 ^ 1 = A〜3
H = D ^ 2 = B ^^ 2 = A ^^^ 2 = A〜2 ^ 2
I = F ^ = B ^ 3 ^ = A ^^ 3 ^
J = F ^ 2 = B ^ 3 ^ 2 = A ^^ 3 ^ 2


When I specify an ancestor commit object in Git, I'm confused between HEAD^ and HEAD~.

Both have a "numbered" version like HEAD^3 and HEAD~2.

They seem very similar or the same to me, but are there any differences between the tilde and the caret?

解决方案

HEAD^ means the first parent of the tip of the current branch.

Remember that git commits can have more than one parent. HEAD^ is short for HEAD^1, and you can also address HEAD^2 and so on as appropriate.

You can get to parents of any commit, not just HEAD. You can also move back through generations: for example, master~2 means the grandparent of the tip of the master branch, favoring the first parent in cases of ambiguity. These specifiers can be chained arbitrarily , e.g., topic~3^2.

For the full details, see "Specifying Revisions" in the git rev-parse documentation.

To have a visual representation of the idea let's quote part of documentation:

Here is an illustration, by Jon Loeliger. Both commit nodes B and C are parents of commit node A. Parent commits are ordered left-to-right.

G   H   I   J
 \ /     \ /
  D   E   F
   \  |  / \
    \ | /   |
     \|/    |
      B     C
       \   /
        \ /
         A

A =      = A^0
B = A^   = A^1     = A~1
C = A^2  = A^2
D = A^^  = A^1^1   = A~2
E = B^2  = A^^2
F = B^3  = A^^3
G = A^^^ = A^1^1^1 = A~3
H = D^2  = B^^2    = A^^^2  = A~2^2
I = F^   = B^3^    = A^^3^
J = F^2  = B^3^2   = A^^3^2

这篇关于Git中HEAD ^和HEAD〜有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆