三つのファイルを比較し,それらの間の差異を表示するため,プログラム @command{diff3}を使用してください(@command{diff3}でファイルのマージも可 能です.see section 共通の先祖からマージ).
"通常の"@command{diff3}の出力書式は,周りの文を用いずに,それぞれの差 異部分のhunkを表示します.hunkには,それが二方向か三方向かに依存してラベ ルが付けられてて,行には,入力ファイルの位置で注釈がつきます.
@command{diff3}の実行方法の詳細は,See section @command{diff3}の呼び出し.
@command{diff3}の出力とオプションでそれを変更する様子を示す例で使用する 三番目のサンプルファイルは,以下のようになります.最初の二つのファイルは, @command{diff}で使用したものと同じです(see section 二つのサンプル入力ファイル).以下 は,`tao'という三番目のサンプルファイルです.
The Way that can be told of is not the eternal Way; The name that can be named is not the eternal name. The Nameless is the origin of Heaven and Earth; The named is the mother of all things. Therefore let there always be non-being, so we may see their subtlety, And let there always be being, so we may see their result. The two are the same, But after they are produced, they have different names. -- The Way of Lao-Tzu, tr. Wing-tsit Chan
それぞれのhunkは`===='で印がついた行で始まります.三方向のhunkには, `===='行があり,二方向のhunkには,そのhunkに差異のある三つの入力ファ イルのいずれかを示す,`1',`2',または`3'が後置されます. hunkには,入力行がどこからのものかを示す一つまたは二つのコマンドが前置さ れている,入力行の二つまたは三つの組のコピーが含まれます.
通常,コマンドごとに異なる入力号のコピーに二つのスペースが前置されます. しかし,@option{-T}や@option{--initial-tab}オプションを用いると, @command{diff3}は二つのスペースの代わりにタブを使用します.これでタブの 行揃えは正しくなります.詳細は,See section タブストップの位置合わせを保持する.
コマンドは以下の形式となります.
入力行の組の最後の行が不完全な場合(see section 不完全な行),出力とは区 別される`\'で始まる行が後置された完全な行になります.
二つまたは三つの入力ファイルの差分の行のグループは,diff3 hunksと 呼ばれ,@command{diff}のhunkに似ています(see section Hunks).@command{diff3} のhunkで三つの入力ファイルがすべて異なる場合,hunkは三方向の hunk(three-way hunk)と呼ばれます.二つの入力ファイルだけが異なる場合, それは二方向のhunk(two-way hunk).
@command{diff}と同様に,いくつかの解が考えられます.ファイル`A', `B',そして`C'を比較するとき, @command{diff3}は通常,二つのコ マンド`diff A B'と`diff A C'で出力される二方向のhunkをマージし て,@command{diff3}のhunkを見つけます.これでは,必ずしも出力が最小にな るわけではありませんが,例外は滅多にないでしょう.
例えば,`F'には三行`a',`b',`f'が含まれていて, `G'に`g',`b',`g'という行が含まれていて,そして `H'に`a',`b',`h'という行が含まれていると仮定します. `diff3 F G H'の出力は以下のようになるでしょう.
====2 1:1c 3:1c a 2:1c g ==== 1:3c f 2:3c g 3:3c h
その理由は,最初のファイルと三番目のファイルの`a'が含まれる二方向の hunkと二番目のファイルの`g'を見つけ,単一行の`b'が三つのファイ ルすべての共通行として見つかり,それぞれのファイルの最後の行に含まれる三 方向のhunkが見つかるためです.
コマンド`diff3 lao tzu tao'の出力は以下のようになります(ファイルの 完全な内容はsee section 三番目の入力ファイルの見本).三つのファイル間で差異のある行 だけが表示されていることに注意してください.
====2 1:1,2c 3:1,2c The Way that can be told of is not the eternal Way; The name that can be named is not the eternal name. 2:0a ====1 1:4c The Named is the mother of all things. 2:2,3c 3:4,5c The named is the mother of all things. ====3 1:8c 2:7c so we may see their outcome. 3:9c so we may see their result. ==== 1:11a 2:11,13c They both may be called deep and profound. Deeper and more profound, The door of all subtleties! 3:13,14c -- The Way of Lao-Tzu, tr. Wing-tsit Chan
Go to the first, previous, next, last section, table of contents.