Method
I can store the timestamp as the AuthorDate
of the first commit.
Since the files are *.ipynb
notebooks, they are not going to be mentioned in any Makefile
, and I want to do it just once, on the initial checkin, so Linus's vehement objection quoted in What's the equivalent of use-commit-times for git? is not applicable in any form.
Store
1 - get the list of files to operate on:
LEGACY_IPYNB=$(git ls-files --others --exclude-standard | grep ipynb)
2 - add the files with git add $LEGACY_IPYNB
.
3 - commit each file separately (YUK! but I cannot do a single commit because the author time is per commit, not per file!):
for f in $LEGACY_IPYNB; do
git commit --date=$(stat -f "%Sm" -t "%FT%T" $f) \
--author="the actual author" -m 'initial commit' $f
done
Recover
1 - extract the initial commit ID (How to reference the initial commit?):
# FIXME: will break if `$f` has been since renamed!
COMMIT=$(git rev-list --max-parents=0 HEAD -- $f)
2 - extract the initial author time:
MTIME=$(git log --pretty=format:%ad --date=format:%Y%m%d%H%M $COMMIT)
3 - modify mtime
of the checked out file:
touch -m -t $MTIME $f