Just do git commit --amend --reset-author --no-edit . For older commits, you can do an interactive rebase and choose edit for the commit whose date you want to modify.
There are actually two different timestamps recorded by Git for each commit: the author date and the commit date. When the commit is created both the timestamps are set to the current time of the machine where the commit was made.
There is no constraint on timestamps in commits. A commit actually has 2 timestamps : a creation date, called "author date" a modification date, called "committer date"
No, it's not. In fact, it's the exact opposite. From the docs of git rebase : "These flags are passed to git am to easily change the dates of the rebased commits".
You should wait a bit.
Or you can do this:
/tmp/x 604% env GIT_AUTHOR_DATE='Wed Dec 19 15:14:05 2029 -0800' git commit -m 'future!'
[master]: created 6348548: "Future!"
1 files changed, 1 insertions(+), 0 deletions(-)
/tmp/x 605% git log
Author: Dustin Sallings <[email protected]>
Date: Wed Dec 19 15:14:05 2029 -0800
Future!
Note that there's both an author date and a committer date, so be sure to set the right one (or both).
You can amend the commit, an example with the year 2037:
git commit --amend --date="Wed Feb 16 14:00 2037 +0100"
I tried the year 2038 too but then I got a null value for the date.
If you want to retain an actual change-date when adding a project to git, you can do so with
env GIT_AUTHOR_DATE="`ls -rt *.cpp|tail -1|xargs date -u -r`" git commit -m "Old sources retaining old change-dates of last changed
file: `ls -rt *.cpp|tail -1`, actual commit date: `date`"
This will commit with the change-date of the last-changed *.cpp-file, and a nice explaining message of the actual commit date.
By combining Hugo's answer (1) with information found over here (2), and tossing in some sed
, I got this:
alias newest="find . -path ./.git -prune -o -type f -exec stat -c \"%y %n\" '{}' + | sort -r | head -1 | sed s#'.*\./'##"
GIT_AUTHOR_DATE="$(newest | xargs date -u -r)" GIT_COMMITTER_DATE="$(newest | xargs date -u -r)" git commit -m "Old sources retaining old change-dates of last changed file: $(newest), actual commit date: $(date)"
The main difference is that this version does a recursive search, so you get the latest file anywhere in the tree - though it does skip the .git directory, intentionally.
You may, of course, want to drop one of the date variables here, and I am using a fairly recent version of bash (4.2.37(1)-release), so the $() notation might not work for you (just replace it with backticks (`) instead).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With