开发者

Adding older versions of code to git repo

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 开发者_JAVA百科1.2 based one?


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)


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜