When I specify an ancestor commit object in Git, I\'m confused between HEAD^ and HEAD~.
Both have a \"numbered\" version like HEAD^3<
Simplistically:
~ specifies ancestors^ specifies parentsYou can specify one or more branches when merging. Then a commit has two or more parents and then ^ is useful to indicate parents.
Suppose you are on branch A and you have two more branches: B and C.
On each branch the three last commits are:
If now on branch A you execute the command:
git merge B C
then you are combining three branches together (here your merge commit has three parents)
and
~ indicates the n'th ancestor in the first branch, so
HEAD~ indicates A3HEAD~2 indicates A2HEAD~3 indicates A1^ indicates the n'th parent, so
HEAD^ indicates A3HEAD^2 indicates B3HEAD^3 indicates C3The next use of ~ or ^ next to each other is in the context of the commit designated by previous characters.
Notice 1:
HEAD~3 is always equal to: HEAD~~~ and to: HEAD^^^ (every indicates A1),and generally:
HEAD~n is always equal to: HEAD~...~ (n times ~) and to: HEAD^...^ (n times ^).Notice 2:
HEAD^3 is not the same as HEAD^^^ (the first indicates C3 and the second indicates A1),and generally:
HEAD^1 is the same as HEAD^,HEAD^n is always not the same as HEAD^...^ (n times ~).