Change commit timestamps in Git
It’s Blogvent, day 2, where I blog daily in December!
Why change commit timestamps?
With my current blogging setup, I write most of my posts in Obsidian, and sometimes TinaCMS. I wrote about that process in detail, here.
This setup still works pretty well for me, BUT something that does kind of bug me is that if I publish a post from TinaCMS, it uses UTC, so it’ll make the commit appear one day later than it actually did, sometimes.
This is just one example, but there’s other times where you might want to change a commit timestamp, like if you are migrating code from another non-Git-based system and you need to update when code was written, or if you want your code to reflect a different time zone, or if you just want your green squares on GitHub to look a certain way (guilty).
Just show me how to edit the timestamp, Cassidy
So to be clear, you can’t directly edit the timestamp of a commit already pushed to GitHub (or wherever you’re pushing your code), but you can rewrite the history and set new dates.
If the commit you want to change is the most recent one, you can run this on a Mac or Linux-based system:
export GIT_AUTHOR_DATE="2025-12-02T23:59:00" # change this to whatever date/time you want
export GIT_COMMITTER_DATE="2025-12-02T23:59:00" # this too
git commit --amend --no-edit --date "$GIT_AUTHOR_DATE"
If you want to do this on Windows, the command in PowerShell is similar:
$env:GIT_AUTHOR_DATE = "2025-12-01T23:59:00"
$env:GIT_COMMITTER_DATE = "2025-12-01T23:59:00"
git commit --amend --no-edit --date "$env:GIT_AUTHOR_DATE"
In Git, each commit stores two timestamps, the author date, and the committer date. The author date is when the work was originally done, set by the author of the commit, and the committer date is when the commit was actually written to the repository. If someone else rebases or cherry-picks or something, this could be a different person or time. You often want these two dates to match, so that’s why you set both in the command here!
Anyway, after running the above, force push it to your repo like so:
git push --force
What if it isn’t the most recent commit?
Ugh. Okay it’s not that bad. But you gotta rebase. You’ll run:
git rebase -i HEAD~3
This would be the last 3 commits, change that number to whatever commit you need to edit.
When you run this, you might see something like this:
pick aaaa111 Commit message 1
pick bbbb222 Commit message 2
pick cccc333 Commit message 3
If you wanted to change the date for the second commit, you’d change that line to say edit instead of pick:
pick aaaa111 Commit message 1
pick bbbb222 Commit message 2
pick cccc333 Commit message 3
(pick means to apply the commit and move on, edit means to stop here and change something)
After you save and close the editor, Git will stop at that commit. This is where you run the commands above with the exporting of variables and git commit --amend stuff.
After you do that, you run git rebase --continue and be on your way.
Unsetting variables
After you do this, you don’t necessarily need to “clean up” your variables, but juuust in case, if you’re about to do more commits and want only one commit to have a changed timestamp, you can unset the variables to avoid accidental reuse.
On Mac/Linux:
unset GIT_AUTHOR_DATE
unset GIT_COMMITTER_DATE
On Windows:
Remove-Item Env:\GIT_AUTHOR_DATE
Remove-Item Env:\GIT_COMMITTER_DATE
Check your work
You can check the commit dates afterwards with:
git log --pretty=fuller
This command gives you a more detailed snapshot than your standard git log, showing both the author and committer info and timestamps.
Hope this was helpful for ya!