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
Alternatively, you can use the Commit with Date VS Code extension to create/amend commits date easily via a graphical interface.
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
Start an interactive rebase for the last X commits:
git rebase -i HEAD~X
In the editor that opens, change
pick
toedit
for the commit you want to change, save and close the editor.Continue the rebase (done automatically if using VSCode Extension above):
git rebase --continue
Repeat 3. and 4. for the rest of the commits
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