I have a branch called staging that contains old commits that I would like to move to two separate branches.
A - B - C - D - E - F - G - H - I staging
I would like to move commits B and C to a new branch: feature-a. Then move commits D, E, and F to a new branch: feature-b.
In the end my branches would look like this:
A - G - H - I staging
A - B - C feature-a
A - D - E - F feature-b
The staging branch is public and other developers may have local versions of it. How can I accomplish this?
NB: There is probably a better way, but here's one way to do it.
Creating
feature-ais easy:We can create
feature-bby creating a new branch based onAand then usingcherry-pick:That
r1..r2expression is documented in thegit-rev-parseman page:Lastly, we can use
git rebase -i --rooton thestagingbranch to remove commits B-F:In my test repository, this results in: