Git
version control
backdate commit
command line
repository

How do I make a Git commit in the past?

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

Git stores both an author date and a committer date for each commit, and you can set either one to an earlier timestamp if you really need to. The mechanics are simple, but rewriting commit dates has consequences for trust, collaboration, and history rewriting, so it should be done deliberately rather than casually.

The Two Dates Git Tracks

Every commit records:

  • 'GIT_AUTHOR_DATE, which represents when the author originally created the change'
  • 'GIT_COMMITTER_DATE, which represents when the commit object was actually written'

In normal everyday commits, those values are the current time. To make a commit appear in the past, set both environment variables before running git commit.

Create a New Backdated Commit

Here is the standard one-off pattern:

bash
1git add .
2
3GIT_AUTHOR_DATE="2024-01-15T10:30:00-0500" \
4GIT_COMMITTER_DATE="2024-01-15T10:30:00-0500" \
5git commit -m "Document legacy migration"

That creates a brand-new commit whose author and committer timestamps both point to January 15, 2024 at 10:30 in the -0500 time zone.

You can inspect the result with:

bash
git log --pretty=fuller -1

The fuller format is useful because it shows both dates explicitly.

Amend an Existing Commit's Date

If the commit already exists and you want to rewrite the most recent one, amend it:

bash
GIT_COMMITTER_DATE="2024-01-15T10:30:00-0500" \
git commit --amend --no-edit --date "2024-01-15T10:30:00-0500"

--date sets the author date. The GIT_COMMITTER_DATE environment variable sets the committer date. Without both parts, the two timestamps may differ.

Rewriting Older Commits

If the commit you want to change is not the latest one, you need history rewriting, usually through interactive rebase.

The common flow is:

  1. Start an interactive rebase covering the commit.
  2. Mark that commit for edit.
  3. Amend the commit with the desired dates.
  4. Continue the rebase.

For the amend step, the command is the same pattern:

bash
GIT_COMMITTER_DATE="2024-01-15T10:30:00-0500" \
git commit --amend --no-edit --date "2024-01-15T10:30:00-0500"

This rewrites commit hashes, so anyone sharing the branch with you will need to reconcile their history afterward.

Accepted Date Formats

Git accepts several date formats, but ISO 8601 style is the safest and clearest:

bash
2024-01-15T10:30:00-0500

Using an explicit time zone avoids ambiguity. Relative forms such as "2 weeks ago" also work, but exact timestamps are better when you want reproducible history.

Why People Do This

Legitimate reasons exist. You may be importing a historical patch, preserving authorship information from another tool, or reconstructing internal history during a repository migration.

That said, backdating commits to make activity look different than it really was can create trust problems. In team environments, rewritten timestamps should have a clear operational reason.

Shared Repositories Need Extra Care

If the commit has already been pushed, changing its date means changing the commit hash. To update the remote branch, you would typically need a force push:

bash
git push --force-with-lease

That is safe only when you understand the branch state and who else is using it. On protected branches, it may not even be allowed.

Common Pitfalls

The first pitfall is setting only the author date and forgetting the committer date. Then git log --pretty=fuller shows mismatched timestamps.

Another pitfall is rewriting history on a shared branch without warning. Even a tiny metadata change produces new commit hashes.

A third pitfall is using vague date strings without a time zone. That makes the result harder to reason about across machines and collaborators.

Finally, do not confuse commit dates with file timestamps. Backdating a commit changes Git metadata, not the file system modification time on disk.

Summary

  • Use GIT_AUTHOR_DATE and GIT_COMMITTER_DATE to create a commit with a past timestamp
  • Use git commit --amend --date ... plus GIT_COMMITTER_DATE to rewrite an existing commit
  • Prefer explicit ISO-style timestamps with time zones
  • Rewriting dates changes commit hashes when the commit already exists
  • Be careful on shared branches because backdating commits is a history rewrite

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.