I have a project which is in serious need of bug-fixing, but I've been developing a few new features as well. I'd like to move all of my recent feature commits into a different branch, because the next release needs to be primarily bug fixes, not untested features. I've seen another thread where it was said that I can use git branch branchname (sha1-of-commit)
to create the branch. Is it possible, once I've created this branch, to move some more recent commits from master into the new branch (the moved commits should no longer appear in the master branch)?
You could git cherry-pick
commits to the new branch. Each cherry-pick
applies the changes of the given commit, effectively copying them.
git checkout branchname
git cherry-pick <sha-of-interesting-commit>
Removing the commits form the master branch is trikcier. If you haven't pushed those commits, you could do an interactive rebase
of master onto itself, and then remove the commits by deleting them from the list of commits presented.
Example: This rebases the last five commits on your current branch
git rebase --interactive HEAD~5
It will present you with a list of commits, where you can delete the ones you don't want
pick 1fc6c95 Patch A
pick 6b2481b Patch B
pick dd1475d something I want to split
pick c619268 A fix for Patch B
pick fa39187 something to add to patch A
See https://help.github.com/articles/interactive-rebase for more info.
Note that cherry-pick
copies, not moves, and rebase --interactive
actually rewrites history by creating a new chain of commits.