This is a special case of rebase, just that the branch is empty:
git checkout A
git rebase B
rebase
is more general; it handles this case also:
Before:
A1 -> A2 -> [A]
/
1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8[B]
After:
A1' -> A2' -> [A]
/
1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8[B]
A1' and A2' are merged to account for the delta between 4 and 8 on the parent branch.
Git rebase handles this trivial case without a hassle. I created a repo with two commits on master
and a branch br
pointing to the first commit.
$ git checkout br
Switched to branch 'br'
$ git rebase master
First, rewinding head to replay your work on top of it...
Fast-forwarded br to master.
Poof, done. The log now shows the branch pointing to the second commit.
We can also achieve this "After": [thanks to M. Flaschen for pointing out this was missing]:
A1'' -> A2'' -> [A]
/
1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8[B]
Instead of rebasing to the branch B, we would name the specific commit 6, e.g.
git checkout A
git rebase 6 # rather than rebase B
When there are no A1 and A2 commits, this reduces to the original question: moving the [A] pointer from 4 to 6.