Note: This is my personal fix for this issue. If you have any better ideas for tscn conflict resolution please let me know:)
As I’ve been collaborating with some friends in Godot projects I’ve come to find the painful experience of git automatically merging the contents of .tscn files. To solve this I eventually landed on creating a custom git merge driver for .tscn files. The merge driver always chooses the incoming file in its entirety if there is a conflict. That way, we might lose some progress but at least the .tscn file is never corrupted.
The solution
1. Create a merge driver script that chooses the incoming file, name it merge_choose_incoming.sh and place it in the root of your project:
#!/bin/bash
cp -f $3 $2
exit 0
2. Add the following to your project’s .git/config
[merge "choose-incoming"]
name = A merge driver that always overwrites changes using the incoming change
driver = ./merge_choose_incoming.sh %O %A %B
3. Assign the merge driver to .tscn files by adding this to your project’s .gitattributes
# Choose the entire incoming file upon merge
*.tscn merge=choose-incoming
Now, when you merge and have a conflict in a .tscn file, the entire incoming file will be chosen, regardless of which one is newer. This means you have to be a bit careful with the order of your merges if you’re doing several branches and which branch you merge into another (i.e. merge main into dev then dev into main, or dev into main then main into dev). Nevertheless I find this to be a better solution than getting corrupted files from the standard merge conflict resolution 🙂

Legg igjen en kommentar