I understand the default Git behaviour of updating the modification time every time it changes a file, but there are times when I want to restore a file\'s original modifica
Just giving my two cents here.
It takes most of what @stefanct proposed but while implementing a similar script I just added a parallel feature.
In my case (1000 files) I went from 60 seconds to 15 seconds to do the operation doing it in parallel.
#!/bin/bash
change_date() {
local dd=`git log -1 HEAD --pretty="%ci" -- $1`
if [ -z "$dd" ];
then echo "$1 is not versionned";
else touch -d "$dd" $1;
fi
}
#list_of_files = find .
list_of_files=`git ls-tree -r -t --full-name --name-only HEAD`
for f in $list_of_files;do
if test "$(jobs | wc -l)" -ge 16; then
wait
fi
{
change_date $f;
} &
done
wait
You can adjust the number of parallel jobs allowed by changing this line
test "$(jobs | wc -l)" -ge 16
The following shell script should work on any POSIX-compatible system to set the modification and access timestamp of all tracked files (and directories). The only downside I could determine yet is that it is quite slow but that's fine for my use case (setting the right dates when producing release archives).
rev=HEAD
for f in $(git ls-tree -r -t --full-name --name-only "$rev") ; do
touch -d $(git log --pretty=format:%cI -1 "$rev" -- "$f") "$f";
done
We had the same issue at work, and have been using successfully the git-store-meta perl script by Danny Lin.
It definitely solved the problem indicated in your question.