I have finally migrated our CVS repository to git. Unfortunately we didn’t use branches in CVS but different versions/branches were separated into different subdirectories.
I.E. we have the following directory structure:
/root
/lib
/tools
/src
/v1.0
/v2.0
/v3.5
Is there a way to separate the 3 versions in the src subdirectory into separate branches instead of keeping the directory for each version?
I have found the same question here on Stack Overflow Question 4877053, where the use of git-subtree is proposed, but even after reading the manual for git-subtree, I didn’t understand how to use it to solve my problem.
Can someone give me a more detailed explanation or even another solution?
I’m quite new to git, perhaps that’s why I didn’t understand the subtree manual 😉
Thanks very much for all your anwers!
It depends what you want left in the repository afterwards.
If you want three branches,
v1.0,v2.0,v3.5, all with structure like this:then yes, I’m pretty sure you can do that. You’ll end up with something like this in terms of branch structure:
A,B,Currentbeing commits you’ve committed since you migrated to git, and wherev1.0,v2.0andv3.5are essentially “dead-end” branches. You could do some fancy things if you want to get a branch structure more like:That is, separate
v1.0,v2.0, andv3.5into their own branches, then rebasev1.0ontov2.0,v2.0ontov3.5, andv3.5onto the first commit in the current version.But I’m not sure exactly what you want to do.
Yes, I’m pretty sure you can do this. My methodology is a little … convoluted, I’ll admit, but here goes. Please, be careful and read the man pages – the following commands probably won’t screw everything up, but use at your own risk.
git checkout -b v1.0– get onto a new branch.Remove everything except
v1.0. There are a few ways to do this. This question has some methods for removal of everything except ; I couldn’t get them working for me, it might work better for you.This will remove
src/v2.0and all associated history from the branch.-fisn’t necessary for this filter; butgit-filter-branchdoes some sort of backup (read the man page?) and it might spit errors. It defiantly will the second time you trygit filter-branch.Repeat this to remove
src/v3.5as well.This will leave you with
src/v1.0. You possibly want to shift the source fromsrc/v1.0tosrc; you could run agit filter-branch --subdirectory-filter(read the man page) to get you a directory structure/v1.0-files(contains nothing but the files from subdirectoryv1.0; has moved contents fromv1.0toroot), and then look at the examples in theman git-filter-branchpage (specifically the bottom example) to shift files into a subdirectory. That might be overkill, and you’d then need to merge that into a branch containing all the other stuff thatgit filter-branch --subdirectoryculled; a simplemv v1.0/* .might work, but you’d then have another commit in your history. I don’t know what you’d prefer.So now you’ve got
v1.0in it’s own branch. Yay!Repeat for
v2.0andv3.5.I’m afraid I can’t see this doing anything but giving you … “odd” history, though. Presumably
v2.0has, essentially,v1.0+ improvements; the structure I’ve listed above (three “dead-end” branches) showsv2.0andv3.5don’t build on the previous versions. I’m not entirely sure what kind of history you have, if this is an issue, etc etc.Because you’ve got
v1.0,v2.0andv3.5in their own little branches, you cangit mergethem orgit rebaseetc etc, if you’d prefer a nicer looking history.Hopefully this gives you a little bit to think about; like I said, please read the man pages. 🙂