Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

3
  • This answer is not right for merge commits. If HEAD is following a merge commit, then HEAD^ means the first parent of HEAD, and HEAD^^ (or HEAD^2) means the second parent of HEAD. In a merge commit, the second parent of HEAD is not the same thing as the parent of the parent of HEAD. See Ancestry References in the Git manual. Commented Oct 7, 2022 at 23:05
  • @bhagerty: That is wrong. While HEAD^2 does indeed indicate the second parent of HEAD, HEAD^2 and HEAD^^ are not synonymous. Multiple carets do refer to commits in relation to the first parent, so just as HEAD^^ refers in general to the grandparent of HEAD, HEAD^^ the grandparent of parent of the first commit of HEAD when HEAD is a merge commit; likewise, HEAD^2^ is the parent of the second parent. Commented Oct 9, 2022 at 3:23
  • Thanks, @mipadi. I assume you are correct, though the documentation doesn't come close to making this clear. As far as I can tell, HEAD~~ and HEAD~2 are synonymous, so by analogy, I expected the number operator to work similarly with the caret. From what you are saying, it does not. That is unfortunate. Commented Oct 15, 2022 at 3:24