0

I have some important files that were deleted while resolving git conflicts and doing git merges. When I say deleted, I mean that they still exist in an earlier commit, but their changes were overwritten in later commits. The picture below is a visualization of my git repo, courtesy of SourceTree.

A visualization of my git branches

The files that I want to keep were deleted upon the git commit circled in RED. The commits that contain the deleted files are in the middle PINK-colored branch (between the blue and green circles), and the commit circled in GREEN is when the branch outlined in pink first merged with the branch in the far left.

Here are the questions that I want to know the answer to:

  1. Why did those files as added in the PINK commits get deleted at the commit circled in RED?

  2. How do I get those files and changes back, from the commit just below the commit circled in RED?

1 Answer 1

1
  1. Here is my best guess as to what happened. In the green circle merge, there was conflict, which prevented the automatic merge and commit from taking place that usually happens with a pull. The developer noticed some local changes to files that he did not himself change, so he discarded those changes (those are the changes that were ultimately lost). In the red merge, git sees that those changes were removed in the green merge, and thus propagates those removals to the merge commit.

  2. This is the tricky part; there are a few ways you could go about it, but all of them will eventually entail you manually cherry picking some commits. I can't see how many commits are on each branch both above and below your screenshot, so I'll just assume you will re-do the pink commits. For each pink commit ABC, do git cherry-pick ABC. This will replay those commits onto the branch, bringing back your changes.

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.