reapply zip files into git

Just some interesting code to remember

The Issue

I recently startet a new project, but did not use git for source management. Each time i had a working version, i just zipped the content of the project folder. Now i want to reapply the full history into a git repository.

My Solution

Creating a brand new and empty git repository:

git init repository

I prepared a text file with a date of each zip file and file name:

2017-03-15T13:47:06+0100 v4
2017-03-21T17:49:07+0100 v5
2017-03-24T10:07:55+0100 v6
2017-03-28T18:06:23+0200 v7
...

A small bash script is reading that text file, extracting each zip file and commiting the content into the git repository. By setting GIT_AUTHOR_DATE and GIT_COMMITTER_DATE it applies the old timestamp as the commit date.

#!/bin/bash
cat list.txt | while read -r a; do
  D=`echo $a | cut -f 1 -d \  `;
  F=`echo $a | cut -f 2 -d \  `;
  echo $F;
  unzip -o $F.zip -d repository
  cd repository
  export GIT_AUTHOR_DATE="$D"
  export GIT_COMMITTER_DATE="$D"
  git add -A
  git commit -m "$F ($D)"
  cd ..
done
comments powered by Disqus