I realize (very late, I admit) that OP in fact never asked to delete all of B's history but rather changes, so my first answer, like most others above, is indeed achieving the expected working tree but unfortunately it's at the expense of branch B
's history, which is lost.
So let's suggest here the plumbing way to both preserve full history and achieve the exact tree you wanted to obtain, with git commit-tree
(see doc)
# to be executed from branch B
git reset --hard $(git commit-tree -m "Reset to A" -p $(git rev-parse --abbrev-ref HEAD) $(git rev-parse A)^{tree})
Explanation
The git commit-tree
command broken down :
git commit-tree -m <message> -p <parent> <tree>
<tree>
needs here to be branch A
's tree, we'll get it with $(git rev-parse A)^{tree}
.
<parent>
must point to B
's tip :$(git rev-parse --abbrev-ref HEAD)
- then the above two parameters plus the message are used by the command to produce a new commit,
- and finally
git reset --hard
sets current branch (B
) on the fresh new commit returned by git commit-tree
.
Looks convoluted at first, but a great tool.