HOWTO · Git
Git 用の Source Gear DiffMerge ツールを設定する
この記事では、SourceGear の DiffMerge をデフォルトの difftool として使用するように Git を構成するプロセスについて説明します。
この記事では、SourceGear の DiffMerge をデフォルトの difftool として使用するように Git を構成する方法について説明します。このツールを使用すると、Git のデフォルトの difftool と比較して改善されたビジュアルでマージの競合を簡単に理解できます。
3 方向のファイル比較をサポートしているため、3 方向のマージに理想的なツールです。
ファイルの以前の状態、現在の状態、およびマージ後の結果を表示できます。SourceGear の公式ウェブサイトから DiffMerge をダウンロードしてインストールする必要があります。
Windows で DiffMerge を設定する
デフォルトで DiffMerge ツールを使用するように Git を設定するには、これを .gitconfig ファイルに追加します。
[diff]
tool = DiffMerge
[difftool "DiffMerge"]
cmd = 'C:/Program Files/SourceGear/Common/DiffMerge/sgdm.exe' "$LOCAL" "$REMOTE"
[merge]
tool = DiffMerge
[mergetool "DiffMerge"]
cmd = 'C:/Program Files/SourceGear/Common/DiffMerge/sgdm.exe' -merge -result="$PWD/$MERGED" "$PWD/$LOCAL" "$PWD/$BASE" "$PWD/$REMOTE"
trustExitCode = true
[mergetool]
keepBackup = false
引数の比較パラメーターについては、次のようになります。
- 元のファイルである
$LOCAL。 - 変更されたファイルである
$REMOTE。
Git Bash で git difftool および git mergetool コマンドを実行して、DiffMerge を開くことができます。
または、コマンドプロンプトで以下のコマンドを実行して、.gitconfig ファイルを更新することもできます。
C:\> git config --global diff.tool diffmerge
C:\> git config --global difftool.diffmerge.cmd
"C:/Program\ Files/SourceGear/Common/DiffMerge/sgdm.exe
\"$LOCAL\" \"$REMOTE\""
C:\> git config --global merge.tool diffmerge
C:\> git config --global mergetool.diffmerge.trustExitCode true
C:\> git config --global mergetool.diffmerge.cmd
"C:/Program\ Files/SourceGear/Common/DiffMerge/sgdm.exe
-merge -result=\"$MERGED\" \"$LOCAL\" \"$BASE\" \"$REMOTE\""
MacOS で DiffMerge を設定する
MacOS で DiffMerge を使用するように Git を構成するプロセスは、おそらく最も簡単です。以下のディレクトリがあることを確認してください。
/usr/local/bin/diffmerge
以下のコマンドを実行して、.gitconfig ファイルを更新し、テストします。
git config --global merge.tool diffmerge
git config --global mergetool.diffmerge.cmd "/usr/local/bin/diffmerge --merge --result=\"\$MERGED\" \"\$LOCAL\" \"\$BASE\" \"\$REMOTE\""
git config --global mergetool.diffmerge.trustExitCode true
git config --global mergetool.keepBackup false
git config --global diff.tool diffmerge
git config --global difftool.diffmerge.cmd "/usr/local/bin/diffmerge --nosplash \"\$LOCAL\" \"\$REMOTE\""
git config --global -e コマンドを実行して、.gitconfig ファイルを検査できます。次のようになります。
[diff]
tool = diffmerge
[merge]
tool = diffmerge
...
[mergetool "diffmerge"]
cmd = /usr/local/bin/diffmerge --merge --result=\"$MERGED\" \"$LOCAL\" \"$BASE\" \"$REMOTE\"
trustExitCode = true
[mergetool]
keepBackup = false
[difftool "diffmerge"]
cmd = /usr/local/bin/diffmerge --nosplash \"$LOCAL\" \"$REMOTE\"
Ubuntu で DiffMerge を設定する
Ubuntu での設定は、MacOS と非常によく似ています。同じコマンドを使用しますが、インストール場所を変更します。
コマンドは次のとおりです。
git config --global merge.tool diffmerge
git config --global mergetool.diffmerge.cmd "/usr/bin/diffmerge --merge --result=\"\$MERGED\" \"\$LOCAL\" \"\$BASE\" \"\$REMOTE\""
git config --global mergetool.diffmerge.trustExitCode true
git config --global mergetool.keepBackup false
git config --global diff.tool diffmerge
git config --global difftool.diffmerge.cmd "/usr/bin/diffmerge --nosplash \"\$LOCAL\" \"\$REMOTE\""
それはほとんどそれです。これで、以下のコマンドを実行してテストできます。
$ git mergetool
$ git difftool
要約すると、SourceGear の DiffMerge ツールを使用するように Git を構成する場合は、オペレーティングシステムに基づいてリストされたコマンドで .gitconfig ファイルを更新する必要があります。