# Pretty format
git log --pretty=fuller
# %ci: committer date, %ai: author date (e.g. "2021-06-09 01:18:55 +0800")
git log --graph --pretty=format:'%C(auto)%h%d (%ci) (%ai) <%ce> %s'
Source: https://stackoverflow.com/a/14244466/6805520
-
Set env variables:
export GIT_AUTHOR_DATE="YYYY-MM-DDThh:mm:ss±hh:mm" export GIT_COMMITTER_DATE="YYYY-MM-DDThh:mm:ss±hh:mm"
-
Commit as usual:
git add . git commit -m "Commit message"
-
Unset env variables:
unset GIT_AUTHOR_DATE unset GIT_COMMITTER_DATE
Source: https://garysferrao.github.io/git/commit/date/2015/12/01/change-git-commit-date.html
Disclaimer: The following steps will modify your Git history.
-
Start interactive rebase:
# Interactive rebase git rebase -i HEAD~4 # Last 4 commits
-
Add
exec
command below each commit:# Example pick 4ca564e Do something exec GIT_COMMITTER_DATE="$(exec git show -s --format=%ai)" git commit --amend --no-edit --date "$(exec git show -s --format=%ai)" pick 1670583 Add another thing exec GIT_COMMITTER_DATE="$(exec git show -s --format=%ai)" git commit --amend --no-edit --date "$(exec git show -s --format=%ai)" pick b54021c Add some tests exec GIT_COMMITTER_DATE="$(exec git show -s --format=%ai)" git commit --amend --no-edit --date "$(exec git show -s --format=%ai)"
Source: https://stackoverflow.com/a/58622282/6805520
Source: https://medium.com/hackernoon/change-the-date-of-a-git-commit-eeed8d2c5b9b