~ modifier, the
^ modifier also accepts
an optional number after it.
Rather than specifying the number of generations to go back (what
the modifier on
^ specifies which parent reference to follow from a merge commit.
Remember that merge commits have multiple parents, so the path to choose is ambiguous.
Git will normally follow the "first" parent upwards from a merge commit,
but specifying a number with
^ changes this default behavior.
Enough talking, let's see it in action with some examples.
Here we have a merge commit. If we checkout master^ without the modifier, we will follow the first parent after the merge commit.
git checkout master^
Easy -- this is what we are all used to.
Now let's try specifying the second parent instead...
git checkout master^2
See? We followed the other parent upwards.
The ^ and ~ modifiers can make moving around a commit tree very powerful. Even crazier, these modifiers can be chained together! Check this out:
git checkout HEAD~^2~2
To complete this level, create a new branch at the specified destination. Obviously it would be easy to specify the commit directly (with something like C6), but I challenge you to use the modifiers we talked about instead!