Create a git repo from .tar.gz files with versions as commits

Say you have a bunch of .tar.gz files, each representing a certain version of a program source code. If you want to compare their contents and see what changed, git would help a lot.

So I wrote a script that would do the work for me and create a repository for those file. It then unpacks the .tar.gz files and adds the files to the repository and commits a new version:

#!/bin/bash

mkdir new_repo
cd new_repo
git init
cd ..

for archive in $(ls eth*tar.gz)
do
    tar -xf $archive
    cd new_repo; git rm -rf *; cd ..
    archive_dir=$(basename $archive .tar.gz)
    mv $archive_dir/* new_repo/
    cd new_repo; git add .; git commit -m $archive_dir; cd ..
    rm -rf $archive_dir
done

Comments