简体   繁体   English

git-文件已删除,更改已意外还原,没有还原历史记录

[英]git - files deleted and changes reverted unexpectedly, no history of revert

three of our developers are working on a remote branch (with a local tracking branch of the same name) and somehow between two commits ~40 files were reverted - but there's no history of these files being reverted. 我们的三个开发人员正在远程分支(具有相同名称的本地跟踪分支)上,以某种方式在两次提交之间还原了约40个文件-但是没有还原这些文件的历史记录。 We simply cannot understand how this happened. 我们根本无法理解这是怎么发生的。

Here's a simplified example of what happened: 这是发生的事情的简化示例:

  • Developer Joe adds "System.out.println("Hello") to HelloWorld.java, commits locally and pushes his changes to this remote branch. 开发人员Joe将“ System.out.println(” Hello“)添加到HelloWorld.java,在本地提交并将其更改推送到此远程分支。

  • Several other commits occur on the remote branch (not touching HelloWorld.java) 远程分支上发生了其他一些提交(未触及HelloWorld.java)

  • Developer Jane add "System.out.println("World") to HelloWorld.java, commits locally and pushes her changes to this remote branch 开发人员Jane将“ System.out.println(” World“)添加到HelloWorld.java,在本地提交并将其更改推送到此远程分支

  • Several other commits occur on the remote branch (not touching HelloWorld.java) 远程分支上发生了其他一些提交(未触及HelloWorld.java)

If you check the full log of this file you will see: 如果您查看此文件的完整日志,则会看到:

  • Jane, Added world, 3:00 PM 简,《增添世界》,下午3:00
  • Joe, Added hello, 2:00 PM 乔,您好,下午2:00

So you expect the current state of this file to be: 因此,您希望此文件的当前状态为:

 System.out.println("Hello")
 System.out.println("World")

And sure enough you can do a diff between the commits and see: 并且确实可以在提交之间进行区分,并查看:

 System.out.println("Hello")
+ System.out.println("World")

There is no further changes. 没有进一步的变化。 But actually, the current state is: 但是实际上,当前状态是:

 System.out.println("Hello")

Our situation is more complicated. 我们的情况更加复杂。 In addition to modifications, we also added files, renamed files, etc. All of those changes were reverted: Files added are removed, files renamed are renamed back to their original name, etc. However, no developer ever pushed any commit which reverted these files. 除了修改之外,我们还添加了文件,重命名的文件等。所有这些更改都已还原:删除了添加的文件,将重命名的文件重命名为其原始名称,等等。但是,没有开发人员曾经推送过任何提交来还原这些文件。文件。

We also only used basic pull+push commands as our changes were all isolated from each other everything automerged perfectly fine. 我们还只使用了基本的pull + push命令,因为我们的更改都相互隔离,所以自动合并的一切都很好。 We did not do anything fancy like rebase, cherry pick, etc. 我们没有做任何想做的事情,例如变基,摘樱桃等。

Github has a feature "View comparison between these two commits" and that's essentially the only evidence the changes were reverted. Github具有“查看这两个提交之间的比较”功能,这基本上是更改被还原的唯一证据。

I'm looking for any git commands I can run which will help debug this further. 我正在寻找可以运行的git命令,这将有助于进一步调试。 We're not really sure how to proceed. 我们不太确定如何进行。

Thank you 谢谢

Make sure the changes are happening on the same branch. 确保更改在同一分支上进行。 Commits diffs can show the diff, but they might be on different branches. 提交差异可以显示差异,但是它们可能位于不同的分支上。

Use git bisect between Joe's commit and the latest and check HelloWorld.java to see if the line is there or not at each bisect point. 在Joe的提交和最新提交之间使用git bisect ,然后检查HelloWorld.java以查看在每个bisect点处是否存在该行。

We cherry picked the three lost commits and reapplied them over the current head. 我们樱桃选择了三个丢失的提交,并将它们重新应用到当前头上。 We still cannot explain how this happened. 我们仍然无法解释这是怎么发生的。 It's a little scary. 有点可怕。 But it's no longer an issue. 但这不再是问题。

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

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