Tips & Tricks

Change the Date of a Commit (Author and Committer)

Sometimes you want to change the date of a commit, for example to correct a mistake or to mimic a specific timeline. To fully change a commit's date (so both the author and committer dates are updated and GitHub shows the new date), follow these steps:

Change the Date of the Last Commit

Replace YYYY-MM-DD HH:MM:SS with your desired date and time.

Bash (Linux/macOS/Git Bash):

DATE="YYYY-MM-DD HH:MM:SS"
GIT_AUTHOR_DATE="$DATE" GIT_COMMITTER_DATE="$DATE" git commit --amend --date="$DATE" 

PowerShell (Windows):

$DATE="YYYY-MM-DD HH:MM:SS"
$env:GIT_AUTHOR_DATE=$DATE
$env:GIT_COMMITTER_DATE=$DATE
git commit  --date="$DATE" 

Change the Date of older commits

  1. Start an interactive rebase for the last X commits:

    git rebase -i HEAD~X
  2. In the editor that opens, change pick to edit for the commit you want to change, save and close the editor.

  3. Continue the rebase (done automatically if using VSCode Extension above):

     git rebase --continue
  4. Repeat 3. and 4. for the rest of the commits

  5. Push commit to your branch with the following command (replace branch-name with your target branch):

    git push  origin branch-name

Push commits in multiple times

The following command will not push X last commit(s):

git push origin HEAD~X:branch-name 

Last updated