Jez Jez - 2 months ago 20
Git Question

Resolving a 'both added' merge conflict in git?

I'm rebasing in git, and one conflict I get is 'both added' - that is, exactly the same filename has been added independently in my branch, and in the branch I'm rebasing on.

git status
tells me:

# Unmerged paths:
# (use "git reset HEAD <file>..." to unstage)
# (use "git add/rm <file>..." as appropriate to mark resolution)
#
# both added: src/MyFile.cs


My question is, how do I resolve this? Must I use a merge tool or is there a way I can do it just from the commandline? If I
git rm src/MyFile.cs
, how does git know which file version I want to remove and which I want to keep?

Answer

If you use git rm git will remove all versions of that path from the index so your resolve action will leave you without either version.

You can use git checkout --ours src/MyFile.cs to choose the version from the branch onto which you are rebasing or git checkout --theirs src/MyFile.cs to choose the version from the branch which you are rebasing.

If you want a blend you need to use a merge tool or edit it manually.

Comments