dammIT

A rantbox by Michiel Scholten

Converting a bunch of tarballs to a Git repository


We've all been there. Well, I've been there at least; before discovering the virtues of a real version control system, I just created a snapshot of my projects by tarring and compressing the directory tree. That way I've a bunch of histories locked inside backup dir per project. When I started using Subversion, I've already manually imported these archives into the first revisions of the relevant repositories (which you can see in the history log), but some old stuff was left unversioned.

I recently dusted off a really old directory with an old project of mine I wrote at the university and tried to start it working again, just for fun. This also uncovered the backup dir containing its history. To skip manual labour, I wrote a little quick-n-dirty import script you can use with a (freshly git init Git repo):

#!/bin/bash
if [ -z "$1" ]; then
echo "Missing source directory (dir with the tarballs)"
echo "usage:"
echo " tarball2git.sh <backupdir> <gitrepo>"
elif [ -z "$2" ]; then
echo "Missing git repository directory"
echo "usage:"
echo " tarball2git.sh <backupdir> <gitrepo>"
else
for FILE in `ls -1 $1`; do
#echo $FILE
echo "./$1/$FILE"
echo "$2/$FILE"
cp -a "$1/$FILE" $2
cd $2
tar xf "$FILE"
rm "$FILE"
git add -A
git commit -am "$FILE"
cd -
done
fi
view raw tarball2git.sh hosted with ❤ by GitHub

Type Comment Here (at least 3 chars)