> ## Documentation Index
> Fetch the complete documentation index at: https://docs.diversion.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# UE プラグイン - Diversion でマージ競合を解決する

export const Image = ({src, alt}) => <img src={src} alt={alt} style={{
  width: '90%',
  borderRadius: '1.5rem',
  border: '.3rem solid #555',
  boxShadow: '0 0 1rem #888'
}} />;

チームでプロジェクトに取り組むと、マージ競合に遭遇することはよくあります。これは、複数の人が同じファイルに変更を加え、その変更をマージしようとするときに発生します。
Diversion の `マージ警告` は競合の回避に役立ちますが、それでも発生してしまった場合、このガイドが Unreal Engine プラグインを使用した解決を支援します。

## ステップ 1: マージ競合を作る

マージ競合を発生させるには、2 つの異なるブランチで同じファイルに変更を加える必要があります。

ここでは、Unreal の Third Person Template プロジェクトの `BP_ThirdPersonCharacter` をプラグインで Diversion リポジトリとして初期化した状態のものを使用します。

<img alt="TPS Character - clean" style={{width: '90%', borderRadius: '1.5rem', border: '.3rem solid #555', boxShadow: '0 0 1rem #888' }} src="https://mintcdn.com/diversion-2/tgHOXPild1lTdU_m/images/bp_tps_character_clean.png?fit=max&auto=format&n=tgHOXPild1lTdU_m&q=85&s=64139a10bc6e64ca2425e28dc1809298" width="2558" height="1440" data-path="images/bp_tps_character_clean.png" />

Diversion デスクトップアプリで、新しいブランチを作成し `notify-jump-apex` と名付けます。

<img alt="新しいブランチの作成 - ボタンの場所" style={{width: '90%', borderRadius: '1.5rem', border: '.3rem solid #555', boxShadow: '0 0 1rem #888' }} src="https://mintcdn.com/diversion-2/kHkON9nxKTMPAEAM/images/creating-new-branch-showing-the-button.png?fit=max&auto=format&n=kHkON9nxKTMPAEAM&q=85&s=658fd86168d3ec51dadb6b693ae33e25" width="762" height="1140" data-path="images/creating-new-branch-showing-the-button.png" />

<img alt="新しいブランチの作成 - 実際に作成" style={{width: '90%', borderRadius: '1.5rem', border: '.3rem solid #555', boxShadow: '0 0 1rem #888' }} src="https://mintcdn.com/diversion-2/tgHOXPild1lTdU_m/images/creating-new-branch-actually-creating.png?fit=max&auto=format&n=tgHOXPild1lTdU_m&q=85&s=34871a6f5fe747ff9ba00f59687ce788" width="602" height="361" data-path="images/creating-new-branch-actually-creating.png" />

キャラクターがジャンプの頂点に達したときにイベントを発火するようにしましょう。`BP_ThirdPersonCharacter` ブループリントに、次のように設定します:

（ここではガイドの目的のために簡略化した例です。）

<img alt="ジャンプ頂点の通知" style={{width: '90%', borderRadius: '1.5rem', border: '.3rem solid #555', boxShadow: '0 0 1rem #888' }} src="https://mintcdn.com/diversion-2/HhHa-PhS49hu7GIa/images/set-notify-jump-apex.png?fit=max&auto=format&n=HhHa-PhS49hu7GIa&q=85&s=538f7b36f3dad08f54c1e61dabcd6737" width="965" height="523" data-path="images/set-notify-jump-apex.png" />

いいですね！変更を `notify-jump-apex` ブランチにコミットしましょう。

<img alt="ジャンプ頂点通知のコミット" style={{width: '90%', borderRadius: '1.5rem', border: '.3rem solid #555', boxShadow: '0 0 1rem #888' }} src="https://mintcdn.com/diversion-2/tgHOXPild1lTdU_m/images/commit-notify-jump-apex.png?fit=max&auto=format&n=tgHOXPild1lTdU_m&q=85&s=8130bb43b8426518e4fc6e1f154df2b5" width="619" height="457" data-path="images/commit-notify-jump-apex.png" />

もう 1 つ欲しい「機能」は、キャラクターが攻撃できるようにすることです。`main` ブランチに戻り、前と同じように `attack` という新しいブランチを作成し、ブループリントの正しいバージョンを取得するためにエディターを再起動します。

攻撃ロジックを実装し、`attack` ブランチにコミットしましょう。

<img alt="攻撃ロジックのスタブ" style={{width: '90%', borderRadius: '1.5rem', border: '.3rem solid #555', boxShadow: '0 0 1rem #888' }} src="https://mintcdn.com/diversion-2/HhHa-PhS49hu7GIa/images/stub-for-attack-logic.png?fit=max&auto=format&n=HhHa-PhS49hu7GIa&q=85&s=f92085b0446d50ad2bcb0251aabd0a77" width="761" height="642" data-path="images/stub-for-attack-logic.png" />

さて、マージしましょう！エディターを閉じ、`main` ブランチに戻り、`notify-jump-apex` ブランチをマージします。

<img alt="main ブランチに戻る" style={{width: '90%', borderRadius: '1.5rem', border: '.3rem solid #555', boxShadow: '0 0 1rem #888' }} src="https://mintcdn.com/diversion-2/HhHa-PhS49hu7GIa/images/switch-back-to-main.png?fit=max&auto=format&n=HhHa-PhS49hu7GIa&q=85&s=d0cf97109424d2fe9cfbeb3e4c088452" width="510" height="278" data-path="images/switch-back-to-main.png" />

<img alt="notify-jump-apex を main にマージ" style={{width: '90%', borderRadius: '1.5rem', border: '.3rem solid #555', boxShadow: '0 0 1rem #888' }} src="https://mintcdn.com/diversion-2/tNxAwm8NrThaCp35/images/merge-notify-jump-to-main.png?fit=max&auto=format&n=tNxAwm8NrThaCp35&q=85&s=230d755e6989e5999f1106bd944ff6a5" width="551" height="367" data-path="images/merge-notify-jump-to-main.png" />

競合する変更がなかったため、これはスムーズに完了しました。しかし、`attack` ブランチを `main` ブランチにマージする際はそうはいきません:

<img alt="競合が検出された" style={{width: '90%', borderRadius: '1.5rem', border: '.3rem solid #555', boxShadow: '0 0 1rem #888' }} src="https://mintcdn.com/diversion-2/tgHOXPild1lTdU_m/images/conflicts-detected-in-merge.png?fit=max&auto=format&n=tgHOXPild1lTdU_m&q=85&s=d98e19d447638d8c2246b9d70a4a1ac7" width="371" height="77" data-path="images/conflicts-detected-in-merge.png" />

おっと！マージ競合が発生しました。これはバイナリファイル（`.uasset`）なので、人間が読める形式ではなく、特別なツールなしに手動で解決することはできません。幸いにも Unreal には専用のツールがあります！それを使ってみましょう。

## ステップ 2: マージ競合を解決する

Unreal エディターを開き、`BP_ThirdPersonCharacter` ブループリントを開きます。アイコンに気付きましたか？これは、そのファイルに競合があることを示しています。

<img alt="ブループリントの競合" style={{width: '90%', borderRadius: '1.5rem', border: '.3rem solid #555', boxShadow: '0 0 1rem #888' }} src="https://mintcdn.com/diversion-2/tgHOXPild1lTdU_m/images/conflict-in-bp-tps-character.png?fit=max&auto=format&n=tgHOXPild1lTdU_m&q=85&s=ea06b749871cab581e66846b3086d47b" width="543" height="510" data-path="images/conflict-in-bp-tps-character.png" />

ファイルを右クリックして `Revision Control -> Merge` に移動します。これでマージ解決ツールが開きます。

<img alt="Revision Control - Merge" style={{width: '90%', borderRadius: '1.5rem', border: '.3rem solid #555', boxShadow: '0 0 1rem #888' }} src="https://mintcdn.com/diversion-2/zdFp0wmCrPve5JMp/images/revision-control-merge.png?fit=max&auto=format&n=zdFp0wmCrPve5JMp&q=85&s=8341eea0a02e6c590aa9ed66a1c57a5b" width="581" height="283" data-path="images/revision-control-merge.png" />

<img alt="マージウィンドウ" style={{width: '90%', borderRadius: '1.5rem', border: '.3rem solid #555', boxShadow: '0 0 1rem #888' }} src="https://mintcdn.com/diversion-2/tNxAwm8NrThaCp35/images/merge-tool-empty-window.png?fit=max&auto=format&n=tNxAwm8NrThaCp35&q=85&s=4c89dc2f4f0b019af6bc4b912836729f" width="2554" height="1440" data-path="images/merge-tool-empty-window.png" />

3 つの列は、ファイルのリモート版、ローカル版、ベース版を表します。リモート版は左側にあり、これは受信する変更です。
今回の場合、それは `attack` ブランチからの変更です。上のスクリーンショットで、左の列が `Revision 12` と表示されているのに気付きましたか？
あなたの左の列は違う番号かもしれません。私はこのガイドのスクリーンショットを撮る際にやり直したためです。あなたのは `4` になるはずです。Discord でぜひ教えてください！

真ん中の列はローカル版で、現在のブランチにあるものです。この例では、`main` ブランチの現在の状態で、`notify-jump-apex` ブランチからの変更を含んでいるはずです。
マージ競合をより適切に管理するには、真ん中の列にローカルの変更が表示されていることが重要です。これは Unreal のマージツールの問題のようです。

右の列はベース版で、2 つのブランチの共通の祖先であり、任意です。この場合、テンプレートの元のブループリントを含む `main` ブランチからの 2 番目のコミットです。
ベース版を表示するには、ドロップダウンを開き、その列に表示したい正しいコミットを選択します。コミットにマウスを合わせるとコミットメッセージが表示され、正しいものを特定できます。そのままにしておいても、残りの手順は同じように見えます。

<img alt="マージのベースコミット" style={{width: '90%', borderRadius: '1.5rem', border: '.3rem solid #555', boxShadow: '0 0 1rem #888' }} src="https://mintcdn.com/diversion-2/tgHOXPild1lTdU_m/images/base-branch-for-merge.png?fit=max&auto=format&n=tgHOXPild1lTdU_m&q=85&s=06f3dd54405cd6a1e2cba197472201c4" width="295" height="279" data-path="images/base-branch-for-merge.png" />

`Start Merge` をクリックし、次に `Event Graph` をクリックします。通常のグラフ操作と同様、または `Next` と `Previous` ボタンを使って、変更を移動できます。
ブループリントがバックグラウンドで開いており、変更を加えると真ん中の列にも反映されることに注意してください。

上部には、重要な 3 つのボタンがあります: `Accept Source`、`Accept Target`、`Finish Merge`。`Accept Source` は左の列の変更を採用し、`Accept Target` は真ん中の列の変更を採用し、`Finish Merge` は変更を保存してウィンドウを閉じます。
今回のケースでは、どれも私たちが望むものではありません！両方のブランチの変更を組み合わせたいのです。そのためには、左の列の変更を、バックグラウンドで開いているブループリントに手動でコピーする必要があります。
通常通りにコピー & ペーストし、完了したら `Finish Merge` をクリックします。

Before:

<img alt="マージウィンドウ - Before" style={{width: '90%', borderRadius: '1.5rem', border: '.3rem solid #555', boxShadow: '0 0 1rem #888' }} src="https://mintcdn.com/diversion-2/HhHa-PhS49hu7GIa/images/unreal-blueprint-merge-window.png?fit=max&auto=format&n=HhHa-PhS49hu7GIa&q=85&s=f5b8f7ccff0b0520cfbbcb32a51bcc41" width="2556" height="1440" data-path="images/unreal-blueprint-merge-window.png" />

After:

<img alt="マージウィンドウ - After" style={{width: '90%', borderRadius: '1.5rem', border: '.3rem solid #555', boxShadow: '0 0 1rem #888' }} src="https://mintcdn.com/diversion-2/tNxAwm8NrThaCp35/images/mid-way-three-way-merge.png?fit=max&auto=format&n=tNxAwm8NrThaCp35&q=85&s=035598e09370c0c7c8eba23f9f67e829" width="2561" height="1440" data-path="images/mid-way-three-way-merge.png" />

以上です！Unreal のマージツールを使ってマージ競合を解決できました。ブループリントを再コンパイルすれば準備完了です。
