简体   繁体   English

如何在Git中更改上游的提交日期?

[英]How to change commit date in upstream in Git?

My colleague pushed his commit to our github repository. 我的同事将他的提交推送到我们的github存储库。 Unfortunatlley he has system date set to some 20 days ahead of the real time. Unfortunatlley他的系统日期比实时提前了大约20天。 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? 我发现了这个问题: 如何在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. ,答案显示我是如何做到的,但我不认为它是安全的,因为提交SHA将因为日期更改而被更改,我不确定将根据原始更改会发生什么(错误的日期提交。

So, is it safe to change the dates and push the changed commits? 那么,更改日期并推送更改的提交是否安全? What will exactly happen in the github repository? 在github存储库中会发生什么? 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 ... 到目前为止,我只是注意到github上的网络图不起作用......

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. 您可以通过git push --force使GitHub接受更改,这将更改历史记录。 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. 历史是基于SHA而不是它们发生的时间。 If you look at the dates after doing a rebase you will see changes that occurred 'after' subsequent ones. 如果你看一下rebase之后的日期,你会看到在'后续'之后发生的变化。 So as far as problems with the repo or your code, there is no danger. 因此,对于回购或代码的问题,没有危险。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM