When I specify an ancestor commit object in Git, I\'m confused between HEAD^
and HEAD~
.
Both have a \"numbered\" version like HEAD^3<
If you're wondering whether to type HEAD^
or HEAD~
in your command, just use either:
They're both names for the same commit - the first parent of the current commit.
Likewise with master~
and master^
- both names for the first parent of master.
In the same way as 2 + 2
and 2 x 2
are both 4
- they're different ways of getting there, but the answer is the same.
This answers the question: What's the difference between HEAD^ and HEAD~ in Git?
If you just did a merge (so your current commit has more than one parent), or you're still interested in how the caret and tilde work, see the other answers (which I won't duplicate here) for an in-depth explanation, as well as how to use them repeatedly (e.g.HEAD~~~
), or with numbers (e.g.HEAD^2
). Otherwise, I hope this answer saves you some time.