Reputation: 20244
I have made three commits to master branch and pushed them to remote. The changes should have been minor (applying a bugfix release of a framework), but ran into really big trouble and should therefor have gone into a different branch until the problems are sorted out and can be merged back into the master branch.
Is there a way to move these commits retroactively into a newly created branch and get them out of master branch?
No one has checked out the changes yet, but I expect them to do soon...
Upvotes: 0
Views: 36
Reputation: 13617
First, create a new branch bug-fix that contains the commits, i.e., where branch master currently is:
git checkout -b bug-fix master
This assumes that you have not yet added even more commits on top of the bad ones on branch master. This command also moves you away from branch master because we need this precondition in the next step. Now rewind the master branch locally:
git branch -f master bug-fix~3
Finally, push it out to the remote:
git push origin +master
All the caveats of rewritten and published history apply, of course.
Upvotes: 1