How to commit files to Git with the original timestamp.

(Or an alternative to https://githistorygenerator.com/ that can make you less employable by revealing side projects from the last century.)

I had a few copies of an old project amiga-scroller on an old hard disk image. The files were checked into RCS back in 1996 and 1997. I’d like to move them to Git and see if it can be compiled. As the files have been preserved for so long I’d like to keep the original timestamps.

Assuming we have a folder with some old files, and a repo on GitHub, first init the local folder and link to remote.

git init
git remote add origin git@github.com:nakane1chome/amiga-scroller.git

Install libfaketime. This will replace the dynamic linking for the standard time functions using LD_PRELOAD.

The timestamp can be associated with each file using find -printf "%T@ %p\n".

Start with the oldest version of the source tree. Add and then commit the file to git.

for f in `find .  -type f -printf "%T@ %p\n" | grep -v .git | sort | cut -f2 -d' '`; do  
    git add $f;
    LD_PRELOAD=~/libfaketime/src/libfaketime.so.1 \
        FAKETIME="`stat -c %y $f `" \
        git commit -m "Add $f" ; 
done

At this point copy the newer version of the source into the repo, repeat for just the modified files.

for f in `git status | grep modified | cut -f2 -d':'`; do 
    git add $f;
    LD_PRELOAD=~/libfaketime/src/libfaketime.so.1 \
        FAKETIME="`stat -c %y $f `" \
        git commit -m "Update $f" ;
done

I found a few missing dependencies, so added them independently.

LD_PRELOAD=~/libfaketime/src/libfaketime.so.1 \
    FAKETIME="`stat -c %y exec/types.i `"  \
    git commit -m "Add OS headers"

Then push to GitHub.

git push -u origin master

You should now see the full history.

Activity