7

I asked this question long ago but I still don't know what do ~ and ^ mean in this answer:

If you're talking about a remote branch, say, origin/master, you can use ~ and ^ to refer to ancestor commits relative to a branch the same way you can with local branches

What's the difference?

1

3 Answers 3

7

^ means "(first) parent of". ~ is similar, but it takes a number as an argument and basically means "ancestor of". So, for example:

HEAD = latest commit HEAD^ = HEAD~1 = parent of latest commit HEAD^^ = HEAD~2 = grandparent of latest commit HEAD~100 = 100th ancestor of latest commit 
Sign up to request clarification or add additional context in comments.

1 Comment

It's worth mentioning the meaning of identifiers such as HEAD^2, which is different (the second parent's commit, where there is more than one parent).
5

According to this document, tilde (~) references the linear ancestors of the commit (parent, grandparent, great-grandparent), whereas caret (^) references multiple parents. In cases where there are multiple merge ancestors, each merge source would be a parent.

1 Comment

This answer is correct. The "accepted" answer is incorrect.
4

As the manpage states:

<rev>^, e.g. HEAD^, v1.5.1^0
A suffix ^ to a revision parameter means the first parent of that commit object. ^<n> means the <n>th parent (i.e. <rev>^ is equivalent to <rev>^1). [...]

<rev>~<n>, e.g. master~3
A suffix ~<n> to a revision parameter means the commit object that is the <n>th generation ancestor of the named commit object, following only the first parents. I.e. <rev>~3 is equivalent to <rev>^^^ which is equivalent to <rev>^1^1^1.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.