Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: Change timestamp after pushing

Tags:

git

github

How do I edit a commit's timestamp after (accidentally) pushing it to the remote repository?

I changed my system time clock to test behavior in my app, and forgot to set it back before
git add -u . and git push. Now my GitHub repo shows multiple files that were edited "in a month".

I have followed the advice here – specifically the comments to the OP that recommend git push --force, but unfortunately the edit dates stay the same.

like image 757
Josh Whittington Avatar asked Aug 01 '13 05:08

Josh Whittington


People also ask

How do I change a timestamp on a commit?

Just do git commit --amend --reset-author --no-edit . For older commits, you can do an interactive rebase and choose edit for the commit whose date you want to modify.

Does git force push rewrite history?

The --force option for git push allows you to override this rule: the commit history on the remote will be forcefully overwritten with your own local history. This is a rather dangerous process, because it's very easy to overwrite (and thereby lose) commits from your colleagues.

How do I edit a previous commit?

The git commit --amend command is a convenient way to modify the most recent commit. It lets you combine staged changes with the previous commit instead of creating an entirely new commit. It can also be used to simply edit the previous commit message without changing its snapshot.

Does git commit timestamp?

There are actually two different timestamps recorded by Git for each commit: the author date and the commit date. When the commit is created both the timestamps are set to the current time of the machine where the commit was made.


1 Answers

Well, that article is about changing the commit message, and then force pushing the change. But here in this case, you first need to fix the commit timestamp, before doing the git push --force.

Read this article to see how to fix the timestamp: How can one change the timestamp of an old commit in Git?

And then force the push.

(Btw, on github, it may take a few refreshes before you see the change. Also, I assume you know that you are breaking the history and if somebody else cloned the repo, you broke them, etc etc, right? good!)

like image 142
chris-l Avatar answered Oct 02 '22 16:10

chris-l