Sometimes I want to split my latest work on a branch into a new branch.
# Create a new branch tracking the old branch
git branch -t new-branch
# Reset the old branch to a prior commit
git reset --hard HEAD~3
git checkout new-branch
I expect git rebase
to now do nothing, because the docs say:
All changes made by commits in the current branch but that are not in <upstream>
are saved to a temporary area. This is the same set of commits that would be shown
by git log <upstream>..HEAD; or by git log 'fork_point'..HEAD, if --fork-point is
active (see the description on --fork-point below)....
So new-branch
is reset to old-branch
, and any saved changes are applied. Shouldn't those saved changes include the commits new-branch
pointed to that were no longer reachable from old-branch
?
Instead, new-branch
is reset to old-branch
and the commits disappear.