Search code examples
gitdatetimegit-commit

Committed and Pushed while using a wrong Local time, how dangerous is this ? and can I fix it?


I am working on a feature that require lots of "time traveling" to be test, basically I set my computer to be 2 months ahead from Now and totally forgot about it, when i was doing my commits (using a git client called Fork), I saw that the commits where having the timestamp "of the future", I changed my computer time to Automatic and pushed, went to Github, and the latest commits were using the timestamp of the future (the wrong one).

  1. How dangerous is this ? will it create a conflict ? can it hurt a pull-request ? at the moment the only bad change I am seeing is Github showing the commits in the "wrong" order (because it is respecting the timestamps of the commits)

  2. Is it possible to fix this ? only the dates were wrong in the commits, so I don't have to manually enter the correct time by the second.

Thank you


Solution

  • This should not cause any issues, except maybe confusion in people looking at your commits and wondering why they're in the future. Git commits make a graph and the order is determined by each commit's parent(s), not by the dates in the commits.

    Can it be fixed? Yes, as long as you're willing (and allowed) to rewrite the history and force push it. If it's still sitting in your own fork, that should be no problem at all. See https://stackoverflow.com/a/58622282/3216427