You could try the --date
option of git commit
, as described in this blog post by Alan Kelder:
Modify/Reset timestamp for already committed change
The above works great for uncommitted changes, but what if you committed the changes and would like to modify the AuthorDate
time? Again, git makes that easy for the last commit:
$ git commit --amend --date='<see documentation for formats>' -C HEAD
Modify/Reset timestamps for several already committed changes
But what if you need to go back several commits? I ran into this situation as well and used the following Bash script to reset the AuthorDate
time, here's what it does.
For a list of files, it will get the hash of the last commit for each file, get the last modification date of the file, then reset the author timestamp to the file's actual modification date. Be sure to run it from the toplevel of the working tree (git will complain if you don't).
files="
foo.txt
bar.txt
"
for file in $files; do
dir=""; commit=""; date="";
dir=$(dirname $(find -name $file))
commit=$(git --no-pager log -1 --pretty=%H -- path "$dir/$file")
date="$(stat -c %y $dir/$file)"
if [ -z "$commit" ] || [ -z "$date" ]; then
echo "ERROR: required var \$commit or \$date is empty"
else
echo "INFO: resetting authorship date of commit '$commit' for file '$dir/$file' to '$date'"
git filter-branch --env-filter \
"if test \$GIT_COMMIT = '$commit'; then
export GIT_AUTHOR_DATE
GIT_AUTHOR_DATE='$date'
fi" &&
rm -fr "$(git rev-parse --git-dir)/refs/original/"
fi
echo
done
You could use the above script to reset both the AuthorDate
and CommitDate
(just add GIT_COMMITTER_DATE
to the code above using the example from the Reference below).
Though modifying the CommitDate
for shared repositories sounds messy as you could be confusing others.