DEV Community

Cover image for Commit with a Past Date and Time in Git

Commit with a Past Date and Time in Git

Pradumna Saraf on July 21, 2023

As developers, we sometimes want to change past Git commits. Although true time travel is impossible, Git offers a neat way to commit with past dat...
Collapse
 
gianpiero_errigo profile image
Gianpiero Errigo

Beware that --amend will not modify last commit, it will replace it with a new one, changing repo history.
That could be tricky if someone already cloned the branch.

Collapse
 
pradumnasaraf profile image
Pradumna Saraf

Yes. Thank you.

Collapse
 
gadrawingz profile image
Gad Iradufasha

Thanks for this warning. Someone can make some mistakes!

Collapse
 
noelgamaliel profile image
DIAMONA

Where is place of name the commit?

Collapse
 
pradumnasaraf profile image
Pradumna Saraf

When you don't specify the -m flag for the commit message, a text editor like Vim will open up for you to enter the commit message.

However, I will edit the article and include the -m flag directly in the command itself.

Collapse
 
noelgamaliel profile image
DIAMONA
Collapse
 
jaywilkinson profile image
James Wilkinson

Useful for when you don't want other members of the team to see your screwed up sleeping pattern and 4am redbull-infused commits.

Collapse
 
priddybroderick profile image
Priddybroderick

Thank you for sharing this helpful tip for changing past Git commits! As developers, having the ability to adjust commit dates and times can be valuable for keeping our version history accurate and organized.
It's essential to remember that amending a commit can impact the commit history lane, so we should use this feature responsibly and with caution.

Collapse
 
pradumnasaraf profile image
Pradumna Saraf

Thank you.

Collapse
 
bullbiased profile image
Bull

WOW. I din't knew about this. Thanks for sharing.

Collapse
 
pradumnasaraf profile image
Pradumna Saraf

Thank you.

Collapse
 
gadrawingz profile image
Gad Iradufasha • Edited

Time traveling ain't possible but this way is useful in most cases on behalf of the developer!

More info like this:

Check this answer on Stackoverflow