Change Git Commits DateTime (All Supported formats)
All Possible ways to change a git commits Author/Commit Date Time.
It's Really handy in many scenarios like mirroring a repository from one source to a destination while trying to keep the same history, same commit message same timing for Auther or the commit.
Regardless of your reason, we will keep it short and move straightforwardly to 3 ways to achieve it:
1 — Author DateTime:
$ git commit --amend --date="Thu Mar 16 12:11:12 2022 +0000" --no-edit
2 — Commit DateTime
$ git commit --amend --date="Thu Mar 16 12:11:12 2022 +0000" --no-edit
3 — Set DateTime on Committing:
commit and set the time for both author and commit under the same git command.
$ GIT_AUTHOR_DATE=format:iso8601:"yourISOdate" GIT_COMMITTER_DATE=format:iso8601:"yourISOdate" git commit -m "description"
All Supported DateTime Formats
- rfc2822:
Mon, 3 Jul 2022 17:18:43 +0200
- iso8601:
2022–04–03 17:18:43 +0200
- local:
Mon Jul 3 15:18:43 2022
- short:
2006–07–03
(not in 1.9.1, works in 2.3.0) - relative:
#EX of Relative:
5.seconds.ago,
2.years.3.months.ago,
'6am yesterday'#Usage:
git commit -m "message" --date=format:relative:5.hours.ago
6. raw (reference)
(git 1.6.2, March 2009)
internal raw git format - seconds since epoch plus. timezone (put another way: 'date +"%s %z"
' format)
7. default: Mon Jul 3 17:18:43 2006 +0200
Happy Coding,
Made with ❤️ by Kitani Islam.