Let's say that I have a repo where A is the initial commit, where HEAD
points to commit B, and where branch "foo-branch" points to commit C:
A
|
HEAD -> B
|
foo-branch -> C
|
D
I know I can get foo-branch to point to commit A (two parents up), via relative ref to HEAD, by running
git branch -f foo-branch HEAD~1
...but let's say that instead of going to a parent commit, I want to go to the child commit of foo-branch, commit D. How do I do this using a relative ref to HEAD
?
As a note, in a purely fictional world, if the #
token could be used to reference the opposite of ~
, I could run
git branch -f foo-branch HEAD#2
and it would point foo-branch to commit D. Purely fictional, but it gets my point across.
P.S. - I know that there could be issues if children of commit C branch anywhere down the chain, but for simplicity's sake, let's not incorporate branches into this question.