Unity Merge Recovery
Unity Scene or Prefab Won't Open After a Git Merge
If a Unity scene or prefab will not open after a Git merge, stop before saving over it. Preserve the broken result and all available merge contributors, read the first Unity Console error, check conflict markers and serialization headers, compare with the last good revision, then restore or reconstruct the smallest safe result.
First response checklist
- Create a recovery branch or copy before changing the broken asset.
- Record the merge commit, parent commits, Unity version, and first Console error.
- Do not repeatedly open and save the asset in different Unity versions.
- Search for conflict markers in all changed Unity text assets.
- Compare the file with its last known good revision.
- Restore the minimum valid base and reapply reviewed changes if necessary.
Classify the failure
| Symptom | Likely cause | First action |
|---|---|---|
| Seems to have merge conflicts | Marker lines remain | Search and resolve every conflict block. |
| YAML/parser error | Malformed, truncated, or unsupported serialized text | Inspect the first reported line and compare contributors. |
| Serialized file version error | Wrong Unity version or damaged header | Open with the project version and compare the header with a good asset. |
| Scene opens empty/partial | Objects were dropped or references/roots changed | Compare semantic object and hierarchy changes. |
| Prefab has missing scripts | Script GUID/meta mismatch or removed script | Resolve the m_Script target and related meta history. |
Check for unresolved merge markers
git grep -n -e '^<<<<<<< ' -e '^=======$' -e '^>>>>>>> ' -- \
'Assets/*.unity' 'Assets/*.prefab' 'Assets/*.asset' 'Assets/*.mat'
Also inspect the staged version with git show :path/to/asset during an active merge. A working-tree fix is not enough if an earlier staged copy still contains the broken result.
Compare with the last good asset
git log --follow -- Assets/Scenes/World.unity
git show <good-commit>:Assets/Scenes/World.unity > /tmp/World.good.unity
git diff <good-commit> HEAD -- Assets/Scenes/World.unity
Do not overwrite the broken file immediately. Use the good copy as a reference to identify missing document headers, lost roots, deleted objects, changed script GUIDs, and invalid references.
Recover intended Unity structure
MergeSight merge-result review and recovery can compare the last good revision, branch contributors, and proposed result as Unity objects, hierarchy, components, properties, overrides, GUIDs, fileIDs, and references. If a true 3-way state is available, keep unresolved choices explicit and preview before writing.
When the merged file is too malformed to parse, restore a valid side or last-good revision, then reapply only the reviewed changes in Unity. A smaller reconstruction is safer than hand-repairing a large unknown YAML structure.
Check scripts and references
- Every
m_ScriptGUID resolves to the intended script meta file. - Moved or renamed assets kept their original meta files.
- Local fileID references point to objects that still exist in the file.
- Prefab source GUIDs and source object fileIDs remain valid.
- Scene root and Transform parent relationships remain complete.
- Materials and ScriptableObjects reference existing assets.
Validate the recovered result
- Open the project in the exact Unity version declared by
ProjectVersion.txt. - Allow import to complete and address the first serialization error before secondary errors.
- Open the asset and inspect hierarchy, prefab links, missing scripts, and references.
- Save to a recovery branch and review the resulting diff.
- Run targeted tests, play paths, and builds.
- Add marker and structural checks to CI before merging the recovery.
Avoid destructive shortcuts
- Do not choose complete Ours or Theirs without inventorying lost work.
- Do not delete
.metafiles to force Unity to reimport assets with new GUIDs. - Do not open and save through multiple Unity versions hoping one repairs the file.
- Do not rewrite shared branch history without explicit team coordination.
- Do not accept an empty scene as a valid recovery because the parser error disappeared.
FAQ
Why won't my Unity scene open after a Git merge?
Common causes are unresolved conflict markers, malformed or truncated YAML, wrong serialized file headers, missing script GUIDs, broken references, or lost scene roots and hierarchy records.
Should I restore Ours or Theirs for a broken Unity scene?
Only after identifying what work the other side contains. Preserve all contributors first, then restore a valid base and reapply intended changes if direct repair is unsafe.
Can deleting the Library folder fix a broken merged scene?
Deleting Library can rebuild import caches, but it does not repair malformed source YAML, missing meta files, conflict markers, or wrong references. Preserve the source problem and diagnose it first.
How do I recover a Unity prefab with missing scripts after merge?
Resolve each m_Script GUID against tracked script meta files, restore moved or deleted meta files where appropriate, compare with the last good prefab, and validate representative instances in Unity.
Summary
Stop and preserve
Keep the broken result, merge contributors, commit IDs, and first Console error.
Restore valid structure
Fix markers or rebuild from the smallest valid revision instead of guessing through malformed YAML.
Validate the recovery
Open in the exact Unity version, inspect references and hierarchy, then run tests and CI.
Recovery should preserve evidence and intended work; removing the first parser error is only the beginning.
Next step
If Unity reports marker syntax directly, follow the complete conflict-marker fix guide.