Say I have a git repository and I’ve been working on master, can I retroactively create a branch. For example:
A – B – C – A1 – D – A2 – E
I want to make it look like this:
A - A1 - A2 \ \ B - C - D - E
The specific use case is when I’ve cherry-picked a bunch of commits into an old version branch and it needs to go into multiple older versions and I don’t want to repeat the cherry-pick on all those revision.
Essentially it’s something that would have been good as a feature or topic branch in the first place but wasn’t created like that.
Of course you can. (With Git there isn’t much than you can’t do anyway. 🙂
This will create a new branch, starting from the commit
A. Afterwards you go back to the same commit again, creating another branch:Now you simply have to merge
new-branchandnew-branch2to 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.