Christoph Christoph - 2 months ago 7
Git Question

Is `git merge` able to display every change (w.r. to a common ancestor) as merge conflict?

Assume we have a file

common_ancestor
(
master
)

ok
ok
ok
ok
ok


From there, we change and commit
master
to

ok
change not ok (looking back)
ok
ok
ok
latest change
ok


Now we have a better idea, checkout
common_ancestor
and change it to

ok
ok
ok
This is a really good change
ok
ok


and commit in a new branch
dev
. As I need some developments from
master
, I want to merge
dev
into
master
but I want to decide for every change whether to keep or not. I tried

git checkout master


git merge dev --no-ff --no-commit


But I did not get what I
expected
. What I am looking for is something like:

ok
<<<<HEAD
change not ok (looking back)
====
>>>> HASH
ok
ok
<<<<HEAD
====
This is a really good change
>>>> HASH
ok
<<<<HEAD
latest change
====
>>>> HASH


where conflict markers are visible (see here).

Edit: What I have seen,
git merge dev --no-ff --no-commit
does not highlight the changes - @VonC explained why there are no conflict markers visible (because there are no conflicts!).

Answer

In your case, merging dev to master would simply:

  • add the change from dev "This is a really good change"
  • keep the change introduced in master "change not ok (looking back)"

That is because those changes were not made at the same spot in the file: there is no concurrent modification at the same line.
That means there is no conflict.

If you want to have a look after a merge (but before the merge commit), you can set up a custom merge driver.

[merge "verify"]
        name = merge and verify driver
        driver = ./merge-and-verify-driver %A %O %B

You can associate that driver to your files in a .gitattributes file.

*.R merge=merge and verify driver

With merge-and-verify-driver.sh a script which always return 1, in order to indicate that there was a conflict, even if the merge was actually resolved without conflicts (which is the case here: no conflict in your merge).

#!/bin/bash
git merge-file "${1}" "${2}" "${3}"
exit 1

Note: In case of conflicts, you will have more information with:

git config --global merge.conflictstyle diff3
Comments