Forcing 'git merge' to declare all differences as a merge conflict

前端 未结 3 881
一生所求
一生所求 2021-02-09 19:20

In a \'git merge \' I would like any difference, even if not normally a merge conflict, to be considered a merge conflict. Then, with \'git mergetool\' I can see and resolve ea

3条回答
  •  一生所求
    2021-02-09 19:39

    You didn't merge. Your command git merge add-on executed a "fast-forward", which means it just moved the branch head. This is because your add-on branch was descended from the tip of your master branch already, so no merge was needed. If you run git log you'll see there's no merge commit.

    Basically, it looked like this before the merge:

                  master
                 /
    o---o---o---o           add-on
                 \         /
                  o---o---o
    

    and the merge just moved the master pointer to the end of the line:

                              master, add-on
                             /
    o---o---o---o---o---o---o
    

    If you want to force a merge, pass the --no-ff flag, as in git merge --no-ff add-on.


    Upon further reflection, the merge attribute won't do what you want. This only applies to file-level merges, which means both sides of the merge has changes to the specific file. If only one side has changes (which is your case), no file-level merge is done and the changed file is accepted unconditionally.

    Your best bet is probably to use git merge --no-ff --no-commit add-on to produce the merge but don't actually commit. You can now inspect the results and tweak them to your satisfaction before committing the merge. If you want to accept changes on a per-hunk basis you can do something like git reset to reset the index and then git add -p to do per-hunk staging.

提交回复
热议问题