30

I don't understand why "both deleted" is a status for unmerged paths.

If:

  • OldStandard is the base
  • NewStandard is the last commit on the trunk
  • OldCustom is the branch (fork from OldStandard) we try to merge back in master

Why is there a conflict with some files marked as "both deleted"?

I understand the conflict for "both added", when one file is added in NewStandard, and another version of the file is added in OldCustom.

But, for deletion, what's the problem if the file has been deleted in NewStandard, and has also been deleted in OldCustom? That's an equivalent state, nope?

user3341592
  • 1,419
  • 1
  • 17
  • 36
  • 3
    Git needs to associate a commit hash with the deletion. Which commit should take ownership of the deletion here? – Tom Jul 03 '17 at 09:49
  • Possible duplicate of [Reproducing Git merge conflict: DD](https://stackoverflow.com/questions/43702944/reproducing-git-merge-conflict-dd) – LeGEC Jul 03 '17 at 12:00

1 Answers1

22

As stated in this answer (suggested as a duplicate) :

you can see a "both deleted" when branchA has a git mv oldfile newstandard commit, and branchB has a git mv oldfile newcustom commit.

In that case, when trying to merge customBranch into standardBranch, git will report a conflict on three files :

both deleted:  oldfile
added by them: newcustom
added by us:   newstandard

Like any conflict, the final choice resides in your hands :

git merely highlight the fact that maybe there could be a problem in the fact that newcustom and newstandard live together in your final code version, and maybe this could be linked to the fact that both were created by being a copy of oldfile.

You get to manually fix that :

  • if removing oldfile is the expected outcome : git reset -- oldfile,
  • if keeping newstandard is the expected outcome, remove the other : git reset newcustom && git rm newcustom,
  • if some parts of newstandard and newcustom should be merged : edit them by hand, or use a 3-way merge tool : meld newstandard newstandard newcustom
  • etc ...
Robin Green
  • 32,079
  • 16
  • 104
  • 187
LeGEC
  • 46,477
  • 5
  • 57
  • 104
  • In that case, how can we decide which things to keep? It'd make sense to accept the deletion, and then either `newcustom` or `newstandard` when finalizing the merge. But how can we clearly see we have to make a choice between those 2 files (when there are hundreds of conflicts)? Using `git mergetool` does not help here, am I right? – user3341592 Jul 03 '17 at 12:36
  • @user3341592: you are right, `mergetool` will show you the "correct" 3 way merge only when solving a "both modified" conflict on one single file. – LeGEC Jul 03 '17 at 14:14