Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a folder containing many files of the form svs_a.png, svs_b.png, svs_xyz.png, svs_something.png, ... svs_final.png. These are all different versions of the same file named according to the bad old "rename each version" system. The folder has now become too cluttered though, and I'm feeling like an idiot for not using a proper VCS from the start. I'd like to pull these all into a git repo now, and it would be great if I could pull each of these into the repo as different versions of the same file. Is there a way to make git do that?

There's also a few files named svs_color_a.png, ... svs_color_final.png which I'd like to store in a different branch of the repo (say named "color").

share|improve this question

1 Answer 1

Assuming a Linux system:

#!/bin/sh -e
import_files() {
    for file; do
        date=$(stat -c %y "$file")
        cp "$file" svs.png; git add svs.png
        git commit -m "Imported $file" --date="$date"
    done
}
git init
import_files svs_{first,second,third,fourth,.....,final}.png
git checkout --orphan color
import_files svs_color_{first,second,third,...,final}.png

Using git checkout --orphan creates a completely separate branch. Using git checkout -b instead would create a branch continuing from the last commit in master.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.