当我在Git中指定一个祖先提交对象时,我混淆了HEAD^和HEAD~。
两者都有“编号”版本,如HEAD^3和HEAD~2。
在我看来它们非常相似或相同,但是波浪号和插入符号之间有什么不同吗?
当我在Git中指定一个祖先提交对象时,我混淆了HEAD^和HEAD~。
两者都有“编号”版本,如HEAD^3和HEAD~2。
在我看来它们非常相似或相同,但是波浪号和插入符号之间有什么不同吗?
当前回答
简单地说,对于亲子关系的第一级(祖先,继承,世系等),HEAD^和HEAD~都指向同一个提交,它位于HEAD(提交)之上的一个父级。
此外,HEAD^ = HEAD^1 = HEAD~ = HEAD~1。但是HEAD^^ != HEAD^2 != HEAD~2。然而头^^ =头~2。继续读下去。
在第一级亲子关系之外,事情变得更加棘手,特别是如果工作分支/主分支有合并(来自其他分支)。还有一个插入符号的语法问题,HEAD^^ = HEAD~2(它们是等价的)但是HEAD^^ != HEAD^2(它们是完全不同的两个东西)。
每个/插入符号指的是HEAD的第一个父代,这就是为什么串在一起的插入符号相当于波浪号表达式,因为它们指的是第一个父代的(第一个父代的)第一个父代,等等,严格基于连接插入符号上的数字或波浪号后面的数字(无论哪种方式,它们都意味着相同的事情),即保持第一个父代并向上x代。
HEAD~2(或HEAD^^)指的是在层次结构中当前提交(HEAD)上/上两级祖先的提交,这意味着HEAD的祖父级提交。
HEAD^2, on the other hand, refers NOT to the first parent's second parent's commit, but simply to the second parent's commit. That is because the caret means the parent of the commit, and the number following signifies which/what parent commit is referred to (the first parent, in the case when the caret is not followed by a number [because it is shorthand for the number being 1, meaning the first parent]). Unlike the caret, the number that follows afterwards does not imply another level of hierarchy upwards, but rather it implies how many levels sideways, into the hierarchy, one needs to go find the correct parent (commit). Unlike the number in a tilde expression, it is only one parent up in the hierarchy, regardless of the number (immediately) proceeding the caret. Instead of upward, the caret's trailing number counts sideways for parents across the hierarchy [at a level of parents upwards that is equivalent to the number of consecutive carets].
所以HEAD^3等于HEAD提交的第三个父结点(不是曾祖结点,即HEAD^^^ AND HEAD~3)。
其他回答
简单地说,对于亲子关系的第一级(祖先,继承,世系等),HEAD^和HEAD~都指向同一个提交,它位于HEAD(提交)之上的一个父级。
此外,HEAD^ = HEAD^1 = HEAD~ = HEAD~1。但是HEAD^^ != HEAD^2 != HEAD~2。然而头^^ =头~2。继续读下去。
在第一级亲子关系之外,事情变得更加棘手,特别是如果工作分支/主分支有合并(来自其他分支)。还有一个插入符号的语法问题,HEAD^^ = HEAD~2(它们是等价的)但是HEAD^^ != HEAD^2(它们是完全不同的两个东西)。
每个/插入符号指的是HEAD的第一个父代,这就是为什么串在一起的插入符号相当于波浪号表达式,因为它们指的是第一个父代的(第一个父代的)第一个父代,等等,严格基于连接插入符号上的数字或波浪号后面的数字(无论哪种方式,它们都意味着相同的事情),即保持第一个父代并向上x代。
HEAD~2(或HEAD^^)指的是在层次结构中当前提交(HEAD)上/上两级祖先的提交,这意味着HEAD的祖父级提交。
HEAD^2, on the other hand, refers NOT to the first parent's second parent's commit, but simply to the second parent's commit. That is because the caret means the parent of the commit, and the number following signifies which/what parent commit is referred to (the first parent, in the case when the caret is not followed by a number [because it is shorthand for the number being 1, meaning the first parent]). Unlike the caret, the number that follows afterwards does not imply another level of hierarchy upwards, but rather it implies how many levels sideways, into the hierarchy, one needs to go find the correct parent (commit). Unlike the number in a tilde expression, it is only one parent up in the hierarchy, regardless of the number (immediately) proceeding the caret. Instead of upward, the caret's trailing number counts sideways for parents across the hierarchy [at a level of parents upwards that is equivalent to the number of consecutive carets].
所以HEAD^3等于HEAD提交的第三个父结点(不是曾祖结点,即HEAD^^^ AND HEAD~3)。
~表示父母。
^如果它有两个或更多的父节点,比如合并提交。我们可以选择父节点中的第二个或另一个。
如果只有一个东西,比如(HEAD~或HEAD^),结果是一样的。
^ BRANCH选择器 git结帐头^2 通过移动到所选分支(在提交树上后退一步),选择(合并)提交的第二个分支。
~提交选择器 git结帐头~2 在默认/选择的分支上向后提交2次
将~和^相对引用定义为PARENT选择器是迄今为止我在互联网上看到的主要定义——包括官方的Git Book。是的,它们是PARENT选择器,但这种“解释”的问题是,它完全违背了我们的目标:如何区分两者……:)
另一个问题是当我们被鼓励使用^ BRANCH选择器进行COMMIT选择时(也就是HEAD^ === HEAD~)。 同样,是的,你可以这样使用它,但这不是它的设计目的。^ BRANCH选择器的向后移动行为是一个副作用,而不是它的目的。
只有在合并提交时,才可以将数字分配给^ BRANCH选择器。因此,只有在需要在分支机构之间进行选择时,才能充分利用其容量。 在fork中表达选择的最直接的方法是踏上所选的路径/分支——这是在提交树上后退一步。这只是一种副作用,而不是它的主要目的。
HEAD~指定“分支”上的第一个父节点。 HEAD^允许你选择一个特定的提交父节点
一个例子:
如果你想要遵循一个分支,你必须指定像这样的东西
master~209^2~15
我的意见…