Is it possible to retroactively turn a set of commits into a branch?

If you want all the commits after revision XXX to have happened in a branch, I find this a lot easier than the other proposed methods.

$ git branch fixes       # copies master to new branch
$ git reset --hard XXX   # resets master to XXX

The commits are now only in the "fixes" branch.

This procedure is described in git's help page for reset under "Undo a commit, making it a topic branch".


Of course you can. (With Git there isn’t much than you can’t do anyway. :)

git checkout -b new-branch hash-of-A
git cherry-pick hash-of-A1
git cherry-pick hash-of-A2

This will create a new branch, starting from the commit A. Afterwards you go back to the same commit again, creating another branch:

git checkout -b new-branch2 hash-of-A
git cherry-pick hash-of-B
git cherry-pick hash-of-C
git cherry-pick hash-of-D
git cherry-pick hash-of-E
git merge new-branch

Now you simply have to merge new-branch and new-branch2 to get the structure you want and drop your old branch.

Of course what Dustin said still holds: the hashes of the commits will change so you should only do that if you haven’t published your changes yet.


You can't do that transparently because the hashes will have to change, but you basically just need to branch HEAD and rebase -i both branches to drop the respective changes.