35

I'm not sure when this error occurs, I haven't found any descriptions in google.

So my colleagues commited some new files and changed files on branch1. I then got these changes and merged them into my branch(branch2) but NOT using git merge but manually using beyond compare (I know it's a bad practice merging manually). However, after merging them manually and copy-pasting the new files in my branch as well, I commited the work in branch2. However, now, when they tried to get some changes from me using git merge origin/branch2 they receive a lot of git "add/add" conflicts on the new files they initially added.

Can anybody tell me why git sees these files as conflicts although they are the same? And how should these conflicts be handled?

Paolo Forgia
  • 6,572
  • 8
  • 46
  • 58
Biggie Mac
  • 1,307
  • 2
  • 13
  • 26
  • 2
    One of the use case of git (Add/Add) conflict may be mode change of file. Affected file in one branch may have different permission than another branch. – Faisal Rehman Aug 21 '17 at 12:02

2 Answers2

48

You get CONFLICT (add/add): Merge conflict in ... conflicts because the files are in fact not the same. You can see the difference using the diff command, for example:

git diff branch1 branch2 -- path/to/file

where branch1 and branch2 are the names of the branches you want to compare.

Or, an easier way to see the difference, right after the failed git merge when you are in the conflicted state, you can simply run git diff without parameters, it will reveal the conflicted regions.

To resolve such conflict, you have to decide which branch has the right content. You can do that by checking out the file from the appropriate branch, for example:

git checkout name_of_branch path/to/file

Sometimes the right content is a mix of the two files. In that case you have to resolve manually, possibly by studying the differences using the git diff command, as in the examples above.

The long-term solution is to avoid making conflicting changes to the same paths in different branches, which is typically a task sharing / communication issue between collaborators.

janos
  • 120,954
  • 29
  • 226
  • 236
  • 1
    Thanks @AndreasFester, I see the same with a recent Git version. Improved my post now. – janos Oct 25 '18 at 16:29
9

I had a git (Add/Add) conflict. The information from Janos provided the insight needed for a solution. The files "appeared" identical, but my conflicting folder of files were added with a permission of 664 on one branch, and a permission of 755 on another branch. Using git status revealed the difference between the files.

Steps taken to resolve the conflict:

git merge --abort
rm -rfv myconflictedfolder
git commit -m'Resolve git Add/Add branch merge conflict by deleting conflicted folder and files in myconflictedfolder'
git merge mybranch
Dana
  • 91
  • 1