Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle/fix git add/add conflicts?

Tags:

git

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?

like image 667
Biggie Mac Avatar asked Oct 20 '13 08:10

Biggie Mac


2 Answers

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.

like image 126
janos Avatar answered Nov 12 '22 19:11

janos


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
like image 8
Dana Avatar answered Nov 12 '22 18:11

Dana