简体   繁体   English

使用 Git 和 Meld for Unity 2019.3+ 设置 Unity Smart Merge

[英]Setting up Unity Smart Merge with Git and Meld for Unity 2019.3+

I looked everywhere for documentation on this matter with little to no success.我到处寻找有关此问题的文档,但几乎没有成功。 Unity's own documentation is very much incomplete when it comes to this dynamic.当涉及到这种动态时,Unity 自己的文档非常不完整。 I am here to provide you with the only way I've been able to get it to work.我在这里为您提供我能够让它工作的唯一方法。 Of course I would appreciate feedback on how this could be done better, but as it stands now nearly all Google searches on this topic are 2 years old or older.当然,我会很感激关于如何做得更好的反馈,但就目前而言,几乎所有关于这个主题的谷歌搜索都是 2 岁或以上。

The Unity docs say to add the following to the .git/config : Unity 文档说要将以下内容添加到.git/config

[merge]
    tool = unityyamlmerge

[mergetool "unityyamlmerge"]
    trustExitCode = false
    cmd = '<path to UnityYAMLMerge>' merge -p "$BASE" "$REMOTE" "$LOCAL" "$MERGED"

The vast majority of the community agrees with that, and also tell you to add either one of these to .gitattributes :绝大多数社区都同意这一点,并告诉您将其中任何一个添加到.gitattributes

*.unity binary
*.prefab binary
*.asset binary

or或者

* text=auto

# Unity files
*.meta -text merge=unityyamlmerge diff
*.unity -text merge=unityyamlmerge diff
*.asset -text merge=unityyamlmerge diff
*.prefab -text merge=unityyamlmerge diff

Neither of which work.两者都不起作用。 I found many different alternatives to the blocks of code above.我发现上面的代码块有许多不同的替代方案。 I looked for days, wasted a whole weekend even.我找了好几天,甚至浪费了整个周末。 Nothing will work and I can't find any current information on the matter.什么都行不通,我找不到有关此事的任何最新信息。

On Windows 10 using Unity 2019.3+ and a current version of Git, this was the only way I could get it to work.在 Windows 10 上使用 Unity 2019.3+ 和当前版本的 Git,这是我可以让它工作的唯一方法。

mergespecfile.txt合并规范文件.txt

First, add the following entries into the mergespecfile.txt to allow Unity's Smart Merge to use the diff tool of your choice.首先,将以下条目添加到mergespecfile.txt以允许 Unity 的 Smart Merge 使用您选择的差异工具。 I'm using Meld here.我在这里使用 Meld。 Note that --auto-merge is optional.请注意, --auto-merge是可选的。 The way I understand it is that it will skip prompting you for a merge.我理解它的方式是它会跳过提示您进行合并。

File Location - Windows: C:\Program Files\Unity\Hub\Editor\<unity version>\Editor\Data\Tools文件位置- Windows: C:\Program Files\Unity\Hub\Editor\<unity version>\Editor\Data\Tools

File Location - Mac: /Applications/Unity/Hub/Editor/<unity version>/Unity.app/Contents/Tools文件位置- Mac: /Applications/Unity/Hub/Editor/<unity version>/Unity.app/Contents/Tools

unity use "%programs%\Meld\meld.exe" "%b" "%r" "%l" -o "%d" --auto-merge
prefab use "%programs%\Meld\meld.exe" "%b" "%r" "%l" -o "%d" --auto-merge
* use "%programs%\Meld\meld.exe" "%b" "%r" "%l" -o "%d" --auto-merge

.gitattributes .git 属性

Next add this to the .gitattributes of your repo.接下来将其添加到您的 repo 的.gitattributes中。 Any file type you specify here will be run through Unity's Smart Merge.您在此处指定的任何文件类型都将通过 Unity 的 Smart Merge 运行。 Anything NOT listed here will default to Git's auto-merge in where you can run git mergetool to invoke our chosen diff tool for the merge.此处列出的任何内容都将默认为 Git 的自动合并,您可以在其中运行git mergetool合并工具来调用我们选择的 diff 工具进行合并。

# Macro for Unity YAML-based asset files.
[attr]unityyaml -text merge=unityyamlmerge diff

# Unity files
*.meta unityyaml
*.unity unityyaml
*.asset unityyaml
*.prefab unityyaml

.git/config .git/配置

Lastly, and this was the worst part to figure out, add the following to your .git/config .最后,这是最糟糕的部分,将以下内容添加到您的.git/config中。 This file is very picky about how syntax is used.该文件对语法的使用方式非常挑剔。 And contrary to the majority of the documentation, it seems like using a merge driver is the only way to get this to trigger.与大多数文档相反,似乎使用合并驱动程序是触发它的唯一方法。

Make sure to change the filepath's to match your version/operating system, and change the merge/diff tool to whichever one you prefer.确保更改文件路径以匹配您的版本/操作系统,并将合并/差异工具更改为您喜欢的任何一个。

[merge "unityyamlmerge"]
    driver = 'C:/Program Files/Unity/Hub/Editor/2019.3.14f1/Editor/Data/Tools/UnityYAMLMerge.exe' merge -p \"$BASE\" \"$REMOTE\" \"$LOCAL\" \"$MERGED\"
    name = Unity SmartMerge (UnityYamlMerge)
    recursive = binary
[diff]
    tool = meld
[difftool "meld"]
    path = C:/Program Files (x86)/Meld/meld.exe
[merge]
    tool = meld
[mergetool "meld"]
    path = C:/Program Files (x86)/Meld/meld.exe
    prompt = false

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM