Move a commit to another branch
September 22, 2022To move the last commit(s) to another branch, first make a new branch (this will include the commits from the current branch):
git branch newbranch
Remove the unwanted commit(s) from the current branch (the command below just removes the latest commit):
git reset --hard HEAD^
To remove N
commits, you can use:
git reset --hard HEAD~N
Now newbranch
has the new commit(s) while the current branch no longer does.