any tools for importing multiple file versions into git?

157 views Asked by At

I somewhat-frequently get myself in the following situation:

I start on what's supposed to be a "small project" (pretty much always a one file script), and decide the project is simple enough that I don't need to version control it with git.

So I work on the script - call it do-thing.py. At some point, I decide I want to do some refactoring, or make some other large change. I decide to make a backup in case it doesn't work out and I want to revert. So, I copy the file and name the copy something like do-thing 1-before big refactor.py.

This goes on, and at some point, I have a folder filled with various old snapshots of the script:

do-thing.py
do-thing 1-before big refactor.py
do-thing 2-before changed function.py
do-thing 3-before alg change.py

where the order from oldest to newest is do-thing 1-*.py, do-thing 2-*.py, do-thing 3-*.py, do-thing.py (although this detail isn't critical to this question).

At this point (with perhaps even more than 3 backups), I realized this project was bigger than expected, and I should have just used version control to begin with. Unfortunately, this realization only comes after I wind up in this situation.

I'd like to convert a series of files like this into a series of git commits. I've done this in the past manually, but wanted to know if there's any existing tooling for it. ideally, it would also use the filename as the commit message.

Are there any existing tools for converting file versions into a git history?

In the git pro book, in this section, there's this quote: "quality importers are available for many other systems, ...even a directory of archives.", suggesting tooling like this exists, but they don't give any references.

In the same section, near the bottom, they give an example script that does this for folders. I was considering just writing my own git fast-exporter for this use case, but I figured this use case must be very common, so I wanted to see about existing options before writing my own.

I wasn't able to find anything online, so I'm asking here. Are you aware of any tools to do this conversion?

1

There are 1 answers

3
VonC On

I am not aware of an existing tool, but I would make a simple script which would:

  • create an empty repo
  • for each work iteration

That is, for each iteration:

cd /path/to/new/repo
git --work-tree=/path/to/do-thing-x add --ignore-removal .
git commit -m "Import iteration x"

As commented, for just one file, that is overkill and slow.
git fast-import is certainly easier.