Git has multiple built-in functions for performing several operations. Changing the commit timestamp is one of them. Timestamp basically keeps the proper record of authors that are added while pushing the changes to the repository. Developers change commit history whenever they want. However, it is not recommended to modify the commit history unless it is necessary for some action.
This write-up will discuss the method of changing the timestamp of an old commit in Git.
How to Change the Timestamp of an Old Commit in Git?
To change the timestamp of an old commit in Git, try the provided instructions:
-
- Go to the Git local repository.
- View the Git reference log history.
- Select the old commit to which you want to change the timestamp.
- Execute the “git commit –amend –date=“<new-timestamp>” –no-edit” command.
- Check the log history for verification.
Step 1: Switch Repository
At first, navigate to the required repository by executing the “cd” command:
Step 2: Select Git Commit
Then, run the provided command to display the current repository log history:
Here, we want to change the timestamp of the most recent commit:
Step 3: Update Timestamp
After that, run the “git commit” command along with the desired timestamp:
In the above-stated command, the “–amend” option is added for updating commits, and “ –date” is a parameter that has the desired timestamp value:
Step 4: Verify Updated Timestamp
To ensure the updated old commit timestamp, run the “git log .” command:
According to the below-provided output, the timestamp has been updated successfully:
We have compiled the easiest way of changing the timestamp of an old commit in Git.
Conclusion
To change the timestamp of an old commit in Git, first, move to the Git local repository and show the Git reference log history. After that, select the old commit to which you want to change the timestamp. Next, run the “git commit –amend –date=“<new-timestamp>” –no-edit” command. Lastly, check the log history for verification. This write-up provided the easiest way of modifying the timestamp of an old commit in Git.