简体   繁体   中英

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. 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.

  • Several other commits occur on the remote branch (not touching HelloWorld.java)

  • Developer Jane add "System.out.println("World") to HelloWorld.java, commits locally and pushes her changes to this remote branch

  • Several other commits occur on the remote branch (not touching HelloWorld.java)

If you check the full log of this file you will see:

  • Jane, Added world, 3:00 PM
  • Joe, Added hello, 2:00 PM

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. 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.

I'm looking for any git commands I can run which will help debug this further. 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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