Friday, 15 April 2011

git import

I had a set of old files with the correct timestamp on, relating to separate versions of a file, ie, foo_16.c, foo_17.c, ... foo_22.c which I wanted to import into a new git repo while preserving the author history

so, this little snippet of code worked - may be useful for others

 
$ git init
$ git add -N foo.c
$ for i in `seq 16 22` ; do
cp -p hist/foo_$i.c foo.c;
GIT_COMMITTER_DATE="`date -R -r foo.c`" git commit \
--author "Fred Bloggs <fred.bloggs@example.com>" \
--date="`date -R -r foo.c`" -m "Version $i" foo.c
done


which you can then branch and commit as normal with current changes

Yes I could probably have done GIT_AUTHOR_DATE=$GIT_COMMITTER_DATE but well, 2 calls to date wasn't that much of an overhead in this case.

anyway, for those that care, the result is up on github

No comments: