Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git retrospective commit

Tags:

git

commit

Before I found the power of git I used to take snapshots of my code and store on my server.

I have an existing git repo for a project I am working on, but I have found some older version on my server that I want to update into git.

Is there a way I can retrospectively add these old version to the repo, keeping the correct sequence development?

like image 814
Andys Avatar asked Feb 27 '26 02:02

Andys


2 Answers

If you haven't published the repository, then create commits out of your snapshots and rebase your branch on top of them.

If you have published the repository and your collaborators don't mind switching over to an entirely new rebased branch (which might require them to rebase their own changes), then you can do the same.

If you have published and you don't want to disturb anyone but still would like to add those commits for documentation purposes, you can create a new root branch separately. At this point you have a choice: leave it at that, or "attach" the branch to your main branch. By "attach", I mean "create a commit with both branches heads as parents, with the state of the main branch". You might call it a "merge commit", but obviously the branches aren't really "merged" since the main branch already reflects the appropriate state. For this, I'd point you to commit-tree and write-tree. This makes the commits easier to discover, though might be confusing to some. You'll probably want to backdate them, too.

Depending on what you choose, I encourage you to ask a new question or refine your current question.

like image 168
tne Avatar answered Feb 28 '26 23:02

tne


I would recommend to do it the other way around. Put the latest of your snapshot sources into a git repo and try to apply all the commits from your current repo. Maybe using git format-patch. If the state of the old source and the first commit of your current repo do not differ to much this should work.

like image 28
NaN Avatar answered Feb 28 '26 23:02

NaN



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!