Sooner or later, most Git users encounter a situation where a commit has the wrong timestamp.
Maybe your system clock was incorrect.
Maybe you imported commits from another repository.
Maybe you rebased a branch and unexpectedly changed commit dates.
Or maybe you're simply curious about how Git stores commit metadata.
In this article, we'll look at how to change the date of an old Git commit and why the process is more complicated than most developers expect.
Why Git Commit Dates Matter
Every Git commit contains more than just code changes.
A commit also stores metadata, including:
- Author
- Committer
- Author Date
- Commit Date
- Commit Message
You can inspect a commit with:
git show --pretty=fuller HEAD
Example:
AuthorDate: Mon Jul 1 10:00:00 2026 +0000
CommitDate: Mon Jul 1 10:00:00 2026 +0000
These timestamps become part of the commit object itself.
This means changing a date creates a new commit hash.
We'll come back to that later.
Changing the Date of the Last Commit
If you only need to modify the most recent commit, Git provides a relatively straightforward solution.
GIT_COMMITTER_DATE="2026-07-01T10:00:00" \
git commit --amend --no-edit --date="2026-07-01T10:00:00"
After running the command:
- Author Date is updated
- Commit Date is updated
- Commit hash changes
You can verify the result:
git show --pretty=fuller HEAD
For a single commit, this approach is usually sufficient.
Changing the Date of an Older Commit
Things become more complicated when the commit is not the latest one.
Imagine a history like this:
A
B
C
D
HEAD
Suppose you want to change the date of commit B.
Git cannot simply modify that commit in place.
Instead, Git must rewrite history.
The typical approach is:
git rebase -i HEAD~4
Git will open an editor:
pick A
pick B
pick C
pick D
Change the target commit:
pick A
edit B
pick C
pick D
Save and exit.
Git stops at commit B.
Now amend the date:
GIT_COMMITTER_DATE="2026-07-01T10:00:00" \
git commit --amend --no-edit --date="2026-07-01T10:00:00"
Continue the rebase:
git rebase --continue
Git rebuilds the remaining commits on top of the modified commit.
Why This Changes Commit Hashes
Many developers are surprised by what happens next.
The code hasn't changed.
The files haven't changed.
The commit message hasn't changed.
Only the timestamp changed.
Yet Git generates a completely different commit hash.
This happens because Git hashes the entire commit object.
The commit hash depends on:
- Tree
- Parent commit
- Author
- Author Date
- Committer
- Commit Date
- Commit Message
Changing any of these fields creates a new object.
Even changing a timestamp by one second produces a different SHA.
Changing Dates for Multiple Commits
Now imagine changing the dates of 20 commits.
Interactive rebase becomes tedious.
You need to:
- Stop at each commit.
- Amend metadata.
- Continue the rebase.
- Resolve conflicts if they appear.
For larger repositories this quickly becomes painful.
Historically, developers used tools like:
git filter-branch
or
git filter-repo
to rewrite commit metadata in bulk.
These tools are powerful but can be intimidating if you don't regularly rewrite Git history.
Be Careful With Shared Branches
Before changing commit dates, remember that history rewriting affects commit hashes.
If you've already pushed commits:
git push origin main
and later rewrite dates:
git rebase -i
you'll need to force push:
git push --force-with-lease
This can disrupt teammates who already based work on the old history.
As a general rule:
- Rewriting local history is usually safe.
- Rewriting shared history requires caution.
A Simpler Alternative
After working with Git history rewriting for a while, I realized that changing commit dates often involves more commands than expected.
For a single commit:
git commit --amend
is manageable.
For multiple commits, interactive rebases become tedious and error-prone.
That's one of the reasons I built GitEditDate — a small tool that helps edit Git commit timestamps without manually stepping through complex rebase workflows.
Whether you use GitEditDate or standard Git commands, understanding how commit dates work makes history rewriting much less intimidating.
Final Thoughts
Changing the date of an old Git commit is possible, but Git intentionally makes it explicit.
A timestamp is not just a label attached to a commit.
It's part of the commit object itself.
Because of that:
- Changing a date changes the commit hash.
- Changing an old date rewrites history.
- Rewriting history affects every descendant commit.
Once you understand those rules, modifying commit dates becomes much easier to reason about.
And if you've ever wondered why a simple timestamp change can trigger a cascade of new commit hashes, now you know the answer.
Top comments (0)