How do I fix a merge conflict due to removal of a file in a branch?

后端 未结 3 1298
不知归路
不知归路 2020-11-30 17:46

I have create a dialog branch and when I try to merge it to master branch. There are 2 conflicts. I don\'t know how to resolve CONFLICT (del

相关标签:
3条回答
  • 2020-11-30 18:03

    The conflict message:

    CONFLICT (delete/modify): res/layout/dialog_item.xml deleted in dialog and modified in HEAD
    

    means that res/layout/dialog_item.xml was deleted in the 'dialog' branch you are merging, but was modified in HEAD (in the branch you are merging to).

    So you have to decide whether

    • remove file using "git rm res/layout/dialog_item.xml"

    or

    • accept version from HEAD (perhaps after editing it) with "git add res/layout/dialog_item.xml"

    Then you finalize merge with "git commit".

    Note that git will warn you that you are creating a merge commit, in the (rare) case where it is something you don't want. Probably remains from the days where said case was less rare.

    0 讨论(0)
  • I normally just run git mergetool and it will prompt me if I want to keep the modified file or keep it deleted. This is the quickest way IMHO since it's one command instead of several per file.

    If you have a bunch of deleted files in a specific subdirectory and you want all of them to be resolved by deleting the files, you can do this:

    yes d | git mergetool -- the/subdirectory
    

    The d is provided to choose deleting each file. You can also use m to keep the modified file. Taken from the prompt you see when you run mergetool:

    Use (m)odified or (d)eleted file, or (a)bort?
    
    0 讨论(0)
  • 2020-11-30 18:15

    If you are using Git Gui on windows,

    1. Abort the merge
    2. Make sure you are on your target branch
    3. Delete the conflicting file from explorer
    4. Rescan for changes in Git Gui (F5)
    5. Notice that conflicting file is deleted
    6. Select Stage Changed Files To Commit (Ctrl-I) from Commit menu
    7. Enter a commit comment like "deleted conflicting file"
    8. Commit (ctrl-enter)
    9. Now if you restart the merge it will (hopefully) work.
    0 讨论(0)
提交回复
热议问题