Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change commit date in upstream in Git?

Tags:

git

github

My colleague pushed his commit to our github repository. Unfortunatlley he has system date set to some 20 days ahead of the real time. So all (4) his commits have wrong date. I would like to change the dates in these commits, but some additional work is already done based on these wrong-dated commits.

I found this SO question: How can one change the timestamp of an old commit in Git? , which answers show how I can do it, but I dont think it is safe as the commit SHAs will be changed beacuse of teh date change and I am not sure what will happen to the changes which were based on the original (wrong-dated) commits.

So, is it safe to change the dates and push the changed commits? What will exactly happen in the github repository? I presume completely new commtis will be created and the old ones will still be there anyway ...

On other hand if I leave the wrong-dated commits as tehy are now, what is the danger? So far I just noticed that the network graph on github does not work ...

like image 960
Ondrej Peterka Avatar asked Nov 13 '22 06:11

Ondrej Peterka


1 Answers

You can change the commits which will result in a new history. You can make GitHub accept the changes via git push --force which will change the history. However doing that will cause trouble for the other dev's that are pulling from the repo (they will likely have to reclone it).

The history is based on the SHA's not when they occurred. If you look at the dates after doing a rebase you will see changes that occurred 'after' subsequent ones. So as far as problems with the repo or your code, there is no danger.

like image 85
Schleis Avatar answered Nov 15 '22 05:11

Schleis