Git

Is There a “git touch” so I Can Push the Same File With a New Timestamp?

When users commit changes in Git, the commits are saved with the timestamp according to the timezone of the user’s system. More specifically, each commit has two dates, i.e., the “commit date” and the “author date”. Users can change/modify the commit history and view when the changes that were made in the past. However, it is not suggested to change the commit history unless it is essential for some operation.

This write-up will illustrate the method to push the same file with a new/different timestamp.

Is There a “git touch” to Push the Same File With a New/Different Timestamp?

No, there is no “git touch” command in Git to push the same file with a new or different timestamp. However, users can push the same file with a new/different timestamp using a different method. To do so, try out the below-provided steps.

Step 1: View Commit History

First, check the Git log to view the commit history including the commit’s timestamp:

$ git log --raw

 
Here, the “–raw” option is used to show the detailed information of the commit.

In the below image, the highlighted part shows the timestamp and file name:


Step 2: Make Changes in File

Next, modify the file’s content to make changes in the same “Test1.txt” file:

$ echo "This is my test file" >> Test1.txt

 

Step 3: Track Changes

Then, save the newly added changes to the Git index using the below-stated command:

$ git add Test1.txt

 

Step 4: Commit File With New Timestamp

Now, execute the provided command to commit the same file with the new timestamp:

$ git commit --allow-empty -m "Commit with new timestamp"

 

Step 5: Verify Changes

Lastly, ensure that the file has been pushed to the local repository with the new timestamp using the following command:

$ git log --raw

 
It can be observed that the file has been pushed successfully with the new timestamp:


We have explained the procedure to push the same file with a new timestamp.

Conclusion

To push the same file with the new or different timestamp, first, navigate to the local repository. Modify the file and track changes. Then, run the “git commit –allow-empty -m “<commit-message>”” command to push the file to the local repository with the new timestamp. Lastly, verify the changes. This write-up illustrated the method to push the same file with a new timestamp.

About the author

Laiba Younas

I have done bachelors in Computer Science. Being passionate about learning new technologies, I am interested in exploring different programming languages and sharing my experience with the world.