How to Commit to Git with a Previous Date (Step-by-Step Guide)
Learn how to commit to Git with a previous date using VS Code. Set author and committer dates, understand Git date formats, and verify commit timestamps.

Have you ever needed to create a Git commit with a previous date? Maybe you're testing a project, working with historical data, or trying to understand how Git handles commit timestamps.
Git normally uses the current date and time when you create a commit. However, it also allows you to specify a custom date for a commit using a few simple commands.
In this guide, I'll show you how to commit with a previous date using Git in VS Code, including how to set both the author date and the committer date.
Table of Contents
- What Is a Git Commit Date?
- How to Commit with a Previous Date in VS Code
- Understanding the Git Date Format
- How to Verify the Commit Date
- How to Push the Commit to GitHub
- Common Mistakes to Avoid
- Final Thoughts
What Is a Git Commit Date?
Before running any commands, it's important to understand that Git stores two different timestamps for each commit.
1. Author Date
The author date represents when the change was originally authored. It can be specified manually when creating a commit.
2. Committer Date
The committer date represents when the commit was created or last applied to the repository history. Git normally sets this to the current date and time.
When you use Git's --date option, it changes the author date, but the committer date usually remains the current time.
If you want both dates to be in the past, you need to set them separately.
How to Commit with a Previous Date in VS Code
Let's see how to create a Git commit with a previous date using the VS Code integrated terminal.
Step 1: Open the VS Code Terminal
Open your project in Visual Studio Code.
From the top menu, select:
Terminal → New Terminal
Alternatively, use the keyboard shortcut:
`Ctrl + ``
Make sure the terminal is opened in your Git repository.
Step 2: Stage Your Changes
Before committing, stage the files you want to include.
git add .
This stages all changes in the current repository, except files excluded by Git's ignore rules.
If you want to stage only a specific file, use:
git add path/to/your-file.cs
Step 3: Set a Previous Commit Date
If your VS Code terminal is using PowerShell on Windows, you can set both timestamps using environment variables.
For example, suppose you want the commit date to be October 5, 2026, at 9:45 AM Bangladesh time.
Run the following commands:
$env:GIT_AUTHOR_DATE = "2026-10-05T09:45:00+06:00"
$env:GIT_COMMITTER_DATE = "2026-10-05T09:45:00+06:00"
git commit -m "Update employee module"
Remove-Item Env:GIT_AUTHOR_DATE
Remove-Item Env:GIT_COMMITTER_DATE
That's it! Git will create the commit with the specified author and committer timestamps.
You can replace the example date and commit message with your own values.
Important: These commands are for PowerShell. If you're using Git Bash or another shell, the syntax will be different.
Why Set Both Environment Variables?
You might wonder why we need two environment variables.
The reason is simple:
GIT_AUTHOR_DATEsets the author timestamp.GIT_COMMITTER_DATEsets the committer timestamp.
Setting both ensures that Git records the same specified date for both fields.
The commands above also remove the temporary environment variables afterward, preventing them from affecting subsequent commits in the same terminal session.
Understanding the Git Date Format
The date format used in the example is:
YYYY-MM-DDTHH:mm:ss+HH:MM
Let's break it down.
| Component | Meaning | Example |
|---|---|---|
YYYY | Year | 2026 |
MM | Month | 10 |
DD | Day | 05 |
T | Separator between date and time | T |
HH | Hour in 24-hour format | 09 |
mm | Minutes | 45 |
ss | Seconds | 00 |
+HH:MM | UTC offset | +06:00 |
For example:
2026-10-05T09:45:00+06:00
This represents October 5, 2026, at 9:45 AM in a time zone that is six hours ahead of UTC, such as Bangladesh Standard Time.
Remember that Git accepts several date formats, but using an ISO 8601-style timestamp with an explicit UTC offset makes the intended date and time easier to understand.
How to Commit with Only the Author Date
Sometimes, you only need to change the author date. In that case, you don't need to set both environment variables.
Git provides a simpler option:
git commit --date="2026-10-05T09:45:00+06:00" -m "Update employee module"
This changes the author date while leaving the committer date at its normal value.
Use this approach when you specifically want to set the author timestamp rather than both timestamps.
How to Verify the Commit Date
After creating the commit, you can verify its timestamps using:
git log -1 --format=fuller
Git will display information similar to this:
commit abc123...
Author: Your Name <you@example.com>
AuthorDate: Mon Oct 5 09:45:00 2026 +0600
Commit: Your Name <you@example.com>
CommitDate: Mon Oct 5 09:45:00 2026 +0600
Update employee module
The commit hash and author information will depend on your repository.
Check both AuthorDate and CommitDate to confirm that they contain the expected values.
How to Push the Commit to GitHub
If you want to push the commit to GitHub, use your usual command:
git push
Changing the timestamps does not normally require any special push command if you're adding a new commit to your branch.
However, if you're modifying the date of a commit that has already been pushed, you generally need to rewrite the commit history. That changes the commit hash and may require a force push.
For example:
git push --force-with-lease
Use this carefully. Rewriting shared branch history can disrupt other developers' work.
Common Mistakes to Avoid
Here are a few things to remember when working with Git commit timestamps.
1. Changing only the author date
Using git commit --date does not normally change the committer date. Set both environment variables if you need both timestamps to match.
2. Using the wrong date format
A timestamp such as 2026-10-05T09:45:00+06:00 explicitly identifies the date, time, and UTC offset. Make sure you enter the intended values.
3. Forgetting the time zone
The +06:00 offset represents Bangladesh Standard Time. Using a different offset can change the corresponding time in UTC.
4. Forgetting to clean up environment variables
In PowerShell, remove the temporary variables after committing if you set them manually. Otherwise, they can affect later Git commands in the same session.
5. Assuming the commit date proves when the work happened
Git timestamps are metadata, not independent proof of when someone actually wrote or completed the code. They can be changed manually, so they should not be treated as an audit trail of real working time.
Final Thoughts
Git gives developers control over commit timestamps, which can be useful for testing, reproducing historical scenarios, and understanding how Git stores commit metadata.
If you're using VS Code on Windows, the easiest way to set both timestamps is to use GIT_AUTHOR_DATE and GIT_COMMITTER_DATE in the integrated PowerShell terminal.
Just remember to verify the result with git log -1 --format=fuller and use timestamp changes responsibly, especially when working on shared repositories.
Useful Git commands to remember:
git add .
git log -1 --format=fuller
git push
And if you need to create a commit with a custom date, you now know exactly how to do it.
Share this article

Dabananda Mitra
Software Engineer specializing in scalable backend systems and minimal, effective API design.
Comments
Loading comments...
More Writings
How to Switch Git Branches Without Losing Your Uncommitted Changes
Learn how to use git stash effectively to temporarily save uncommitted changes when you need to switch branches without losing your work.
Read Article →WindowsHow to Kill a Process Using Port in Windows: Complete Guide
Learn how to find and kill a process using a specific port in Windows with netstat, tasklist, and taskkill commands. A practical guide for .NET and ASP.NET Core developers.
Read Article →.NETTop 500 .NET Interview Questions | Complete Preparation Guide
Preparing for a .NET developer interview? I collected 500 unique interview questions covering the most important areas of the .NET ecosystem. This is a useful revision resource for freshers and experienced .NET developers preparing for technical interviews. Save it, practice the questions category by category, and use it as a structured roadmap for your .NET interview preparation.
Read Article →