简体   繁体   中英

Move commits into another branch

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...

First, create a new branch bug-fix that contains the commits, ie, 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM