Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding older versions of code to git repo

Tags:

git

I have a git repo for my project, and my first commit was at v1.2. Before git I used daily snapshots of my code to keep it safe. I would now like to add all of the snapshots I have into the repo as well starting v0.3, but I already have quite a number of commit on top of 1.2. So what's the best way to proceed? Should I just commit the snapshots one by one and add tags? Or should I create another branch perhaps for all these snapshots? Or maybe start a new repo with v0.3 and commit all snapshots then somehow merge the repo with the old 1.2 based one?

like image 778
alian Avatar asked Feb 20 '11 00:02

alian


People also ask

How do I manage multiple versions in Git?

Probably the easiest way is create branches for each version and then do for example git checkout v1. 0.14 or whatever branch you want to work on. The clients can then also check out the appropriate branch for the one they need as well as when upgrading to next version.


2 Answers

Ben's answer is definitely a good way to go if you haven't made this repostory public.

If on the other hand you've already published your current repository, and therefore don't want to transplant its root commit onto the previous work, I'd suggest something disjoint. I'd personally be tempted to just create another branch in the repository called "legacy" or some such, start it at a new root commit with your very first snapshot, and commit all the others on top of it. Presumably the primary use here is just archiving that work, and possibly checking it out or diffing against it at some point - and you'll be able to do all of that even if the history is a little weird:

# No commits in common!

- o - o - o - o - o (master)

- o - o - o (legacy)
like image 113
Cascabel Avatar answered Sep 22 '22 21:09

Cascabel


You can git filter-branch --parent-filter to graft your work onto the old versions, but that will cause problems if you're sharing your repo with anyone else. Everything will get a new SHA. There's really no way to avoid that: The parents (back to the original revision) are part of the SHA of each revision. If you don't care about that (if it's your own personal repo) then go for it.

There is an example in git help filter-branch for doing the exact thing you want.

like image 39
Ben Jackson Avatar answered Sep 24 '22 21:09

Ben Jackson