LoginSignup
4
5

More than 1 year has passed since last update.

UnityでSmart Merge(UnityYAMLMerge)を使用してPrefabの競合を解決する

Posted at

Unityで同一のPrefabやSceneファイルを、異なるブランチで編集してマージすると、確実にコンフリクトします。
ですがUnityYAMLMergeというUnity公式のマージツールを使用すると、多くの場合自動でコンフリクト解消することができます。

ツール設定方法

UnityYAMLMergeはUnity本体と同時にインストールされます。
Macの場合は以下のパスにツールが存在します。

/Applications/Unity/Unity.app/Contents/Tools/UnityYAMLMerge

Unity Hub経由の場合はパスは下記になります。(バージョン番号は適宜変更してください)

/Applications/Unity/Hub/Editor/2018.4.16f1/Unity.app/Contents/Tools/UnityYAMLMerge

パスがわかったら ~/.gitconfig末尾にツール設定を追加します。
YAMLMergeへのパスは適宜変更してください。

~/.gitconfig
#...既存の設定
[merge]
	tool = unityyamlmerge
[mergetool "unityyamlmerge"]
	trustExitCode = false
	cmd = '/Applications/Unity/Unity.app/Contents/Tools/UnityYAMLMerge' merge -p "$BASE" "$REMOTE" "$LOCAL" "$MERGED"

これでツールの設定は完了です。

コンフリクト解消手順

まず下記のようにマージした結果コンフリクトが起きたとします。

$ git merge feature/prefab_conflict_branch
Auto-merging XXXXX.prefab
CONFLICT (content): XXXXX.prefab

この状態でgit mergetoolを実行すると、YAMLMergeがコンフリクト解消を試みてくれます。

$ git mergetool
Merging:
XXXXX.prefab

Normal merge conflict for 'XXXXX.prefab':
  (local): modified file
  (remote): modified file
Conflicts:
Conflict handling:

上記のような形でメッセージが出れば、解消成功なのでそのままマージを進めればOKです。

$ git merge --continue

ツールでも解消できない場合

ツールも万能ではなく、例えば同じTransformコンポーネントを編集した場合、この部分は手動で解消する必要があります。

git mergetool実行後に手動解消が必要な場合、さらに設定されたmergetoolが起動します。
Macの場合は標準のopendiffが立ち上がるので、それで解消していくわけですが、
これの相性が悪くp4merge等の別のmergetoolを設定しておく必要があります。

p4mergeの設定方法はインストール後、下記のようにUnityYAMLMerge設定ファイルに記載します

/Applications/Unity/Unity.app/Contents/Tools/mergespecfile.txt
#
# Default fallbacks for unknown files. First tool found is used.
#

* use "Applications/p4merge.app/Contents/MacOS/p4merge" %b %l %r %d

これで手動解消での対応も可能になりました。

4
5
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
4
5