Search code examples
gitgithubgit-mergegit-pullgit-diff

How do I merge files without conflict in git?


We are two people working on one master branch repo in Github.

And, today I had modified a file in my local copy which I commited, then I wanted to merge my friends change with he pushed to github, so I did:

git fetch
git diff --stat HEAD...HEAD@{upstream}

And I can see

 src/components/views/invoicing/expenses/add.vue  | 106 ++++++--------
 src/components/views/invoicing/expenses/edit.vue | 173 ++++++++++++-----------
 src/components/views/org/Add.vue                 |   4 +-
 src/i18n/de.js                                   |  22 ++-
 src/i18n/en.js                                   |  26 ++--
 src/i18n/fr.js                                   |  11 +-
 src/resources/expensesList.js                    |   4 +-

Now, I can merge all files since I didn't modify them except the src/resources/expensesList.js file which I have modified and committed.

So, git merge origin/master say:

CONFLICT (content): Merge conflict in src/resources/expensesList.js

but all the other files are mergable and okay, so is there anyway to fix the conflict either to instruct git to use my changes or the incoming changes so I can run merge without conflict


Solution

  • By default, when Git cannot merge automatically because of one or more conflicting file(s), it will abort the merge and put markers into the conflicting file(s) that will help you to resolve the conflict manually by making a decision for every single conflicting hunk of code about which version to keep. This behavior can be modified with the -Xours and -Xtheirs flags.

    To merge and always use your version of a conflicting file, use:

    git merge -Xours <branch>
    

    To merge and always use the remote version (in this case, the version of your collaborator) of a conflicting file, use:

    git merge -Xtheirs <branch>
    

    For more details, see the Git Tools - Advanced Merging chapter in the Git documentation.