Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git conflict "both deleted"

Tags:

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?

like image 580
user3341592 Avatar asked Jul 03 '17 09:07

user3341592


People also ask

How do I fix a deleted merge conflict?

Select Stage Changed Files To Commit (Ctrl-I) from Commit menu. Enter a commit comment like "deleted conflicting file" Commit (ctrl-enter) Now if you restart the merge it will (hopefully) work.

How do I accept both changes in git conflict?

The only way to "accept both" would be to just re-stage (marking as resolved) the conflicted files without resolving them ( >>> and <<< would be there still), but your result couldnt be compiled or executed. And this is terrible practice, even if you make commits later to resolve.

What happens if you get a conflict during a merge?

A merge conflict is an event that occurs when Git is unable to automatically resolve differences in code between two commits. When all the changes in the code occur on different lines or in different files, Git will successfully merge commits without your help.


1 Answers

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 ...
like image 159
LeGEC Avatar answered Sep 20 '22 09:09

LeGEC