LoginSignup
34
34

More than 5 years have passed since last update.

merge.conflictstyle=diff3

Posted at

コンフリクトした時にこんなように見えるようになります。

<<<<<<< HEAD
master
||||||| merged common ancestors
original
=======
branch
>>>>>>> tmp

違いは、新しく ||||||| マーカが来てマージべースとなっているコンテンツの出力、その後で ======= マーカが来て…という具合になります。たすかる〜

これを設定するコマンドがこんな感じです。

% git config merge.conflictstyle diff3

ここから以下はつれづれに長々とメモ。

a というファイルがコンフリクトする例えば以下のようなヒストリがあったとします。

            A---B tmp (branch)
           /
   ---C---D---E master (master)
(original)

NOTE: 括弧の中が a というファイルの中のコンテンツです。

ここで、E(masterブランチ)へA-B(tmpブランチ)をマージしようとします。

% git checkout master
Switched to branch 'master'
% git merge tmp
Auto-merging a
CONFLICT (content): Merge conflict in a
Recorded preimage for 'a'
Automatic merge failed; fix conflicts and then commit the result.
% git show :1:a
original
% git show :2:a
master
% git show :3:a
branch
% cat a
<<<<<<< HEAD
master
=======
branch
>>>>>>> tmp
% git diff
diff --cc a
index 1f7391f,80858c1..0000000
--- a/a
+++ b/a
@@@ -1,1 -1,1 +1,5 @@@
++<<<<<<< HEAD
 +master
++=======
+ branch
++>>>>>>> tmp

このような場合。

デフォルトの merge.conflictstyle=merge では、下のように見えます。 上で書いたやつにも出ていますけれども、陽に merge-index を使ってもう一回、

% git -c merge.conflictstyle=merge merge-index git-merge-one-file a
Auto-merging a
ERROR: content conflict in a
fatal: merge program failed
% cat a
<<<<<<< .merge_file_PnZ7aW
master
=======
branch
>>>>>>> .merge_file_NSFnEX

インデックスのステージ1に読み込まれるマージベースのコンテンツ “original” の文字は見えません。 というのは、一方で、 merge.conflictstyle=diff3 では、

% git -c merge.conflictstyle=diff3 merge-index git-merge-one-file a
Auto-merging a
ERROR: content conflict in a
fatal: merge program failed
% cat a
<<<<<<< .merge_file_dEsBt1
master
||||||| .merge_file_zao0b3
original
=======
branch
>>>>>>> .merge_file_efI962

||||||| の後にマージベースのコンテンツが、この場合 “original” が来て、その後に ====== が来るようになります。

In addition to the <<<<<<<, =======, and >>>>>>> markers, it uses another ||||||| marker that is followed by the original text. You can tell that the original just stated a fact, and your side simply gave in to that statement and gave up, while the other side tried to have a more positive attitude. You can sometimes come up with a better resolution by viewing the original.

http://git.kernel.org/?p=git/git.git;a=blob;f=Documentation/git-merge.txt;hb=v1.8.1#l227 git-merge(1)

確かに、場合によったらというか大概がたすかりそうな気がします。嬉しい。

% git config merge.conflictstyle diff3
% git config --get merge.conflictstyle
diff3
% git merge --abort
% git merge tmp
Auto-merging a
CONFLICT (content): Merge conflict in a
Automatic merge failed; fix conflicts and then commit the result.
% git diff
diff --cc a
index 1f7391f,80858c1..0000000
--- a/a
+++ b/a
@@@ -1,1 -1,1 +1,7 @@@
++<<<<<<< HEAD
 +master
++||||||| merged common ancestors
++original
++=======
+ branch
++>>>>>>> tmp

うん上手くいっているようだ。 diff3 プログラムでも試してみよう。

% diff3 -m a =(git cat-file blob master~1:a) =(git cat-file blob tmp:./a) -LHEAD -Lbase -Ltmp
<<<<<<< HEAD
master
||||||| base
original
=======
branch
>>>>>>> tmp

ただここで出てくるオリジナルのコンテンツがあまりにも巨大になっちゃう場合には、もしかしたらばかえってうっとうしい、ということになっちゃうのかしらん。

今まで知らんかったです(^^;

34
34
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
34
34