Skip to content

Instantly share code, notes, and snippets.

@Panakotta00
Last active September 24, 2024 12:54
Show Gist options
  • Save Panakotta00/c90d1017b89b4853e8b97d13501b2e62 to your computer and use it in GitHub Desktop.
Save Panakotta00/c90d1017b89b4853e8b97d13501b2e62 to your computer and use it in GitHub Desktop.
Use the Unreal Editor as Git Diff/Merge Tool

Unreal Engine Asset Diff/Merge-Tool with Git!

Since unreal engines assets are binary encoded classical text based git diff/merge tools will give up on merge conflicts of unreal assets. But fear not! You can setup your git environment to actually be able to diff/merge these .uasset files by using already built-in functionallity of the unreal editor!

Creating the PowerShell-Script

First of all do we have to create a small PowerShell-Script that copies the diff files into temporary files and to convert relative paths to absolute ones. This is necessery since some clients (like GitKraken) mess a bit with the files and Unreal Engine doesn’t seem to be able to use those files properly.

$UE_PATH = "G:/Projects/Satisfactory/SatisfactoryUnrealEngine/Engine/Binaries/Win64/UE4Editor.exe"
$PROJECT_PATH = "G:/Projects/Satisfactory/SatisfactoryModLoader/FactoryGame.uproject"

for ($i = 0; $i -lt $args.length; $i++) {
    $args[$i] = Resolve-Path $args[$i]
    $TempFile = New-TemporaryFile
    Copy-Item $args[$i] -Destination $TempFile
    $args[$i] = $TempFile
}

& $UE_PATH $PROJECT_PATH -diff $args

Replace the UE_PATH and PROJECT_PATH variables with the paths to your installations you want to use.

Save the file at a reasonable place for your git-config, I decided to place it right next to it C:\Users\MyUsername\Git_UE_Diff.ps1.

Adding the Tool to the Git-Config

Now that we have created our trampoline, we have to tell git about or new diff tool. We do this by editing our .gitconfig file. This file is usually placed in your user directory C:\Users\MyUsername\.gitconfig.

Warning
If the file is no visible, try to enable "show hidden files" in the view settings of your windows explorer

In this file we now add a new diff and merge tool. Each tool just simply calls our power shell script and passes the files to diff to the unreal editor in addition to the -diff switch. Also make sure to tell the diff/merge tool that it actually supports binary files.

[diff "CSS_UE_Diff"]
    tool = UE_Diff_Tool
    binary = true
[difftool "UE_Diff_Tool"]
    cmd = "powershell C:/Users/MyUsername/Git_UE_Diff.ps1 \"$REMOTE\" \"$LOCAL\""
[merge "UE_Merge"]
    tool = UE_Merge_Tool
    binary = true
[mergetool "UE_Merge_Tool"]
    cmd = "powershell C:/Users/MyUsername/Git_UE_Diff.ps1 \"$REMOTE\" \"$LOCAL\" \"$BASE\" \"$MERGED\""

Make sure again to replace the paths to your powershell script accordingly.

Now you can use the Unreal Editor as external git diff/merge tool.

File Abbreviations

Additionally you may want to tell git to abreviate the .uasset file extension with the unreal editor. For this, create or open a .gitattributes file in your project and tell git to use your diff/merge tool.

.uasset diff=UE_Diff merge=UE_Merge
@samamstar
Copy link

In that powershell script there's a path to a specific .uproject file. Does that mean this process will only work for git w/ that one project?

@Panakotta00
Copy link
Author

In that powershell script there's a path to a specific .uproject file. Does that mean this process will only work for git w/ that one project?

I'm not sure... but I think so, yes... i think you have to make sepperate tools for sepperate projects

@samamstar

Copy link

ghost commented Jan 12, 2023

took me a while to figure out how to use this so in case anyone else struggles heres how i did it: right click powershell and run as admin, then enter Set-ExecutionPolicy Bypass, then type git difftool -t UE_Diff_Tool

@ColinBou
Copy link

ColinBou commented Jun 8, 2023

Hello
Very nice script.
The command -diff crash with UnrealEditor.exe version 5.1 !
The problem is LFS file :

version https://git-lfs.github.com/spec/v1
<<<<<<< HEAD
oid sha256:5e0c733984ab8c9692bf24e5e9db720a306338401696a29e7b4e3d3e5d19b070
size 846126
=======
oid sha256:961e99ad54483ba261eaa4a112508c9b3eadfea4323f387daeef5516c8d5bd3c
size 836089
>>>>>>> develop-audio

Any idea ?

Does work with unreal engine 5 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment