Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to repair Unity .prefab files in git-lfs after merging

I'm working on a Unity3D project in Unity17.2.1

I use git with Git-LFS and SourceTree on Windows 10.

My problem is now:

On my local clone everything works fine.
But if I clone the project in a new folder (for testing) I get a lot of errors. It downloads the most files tracket by LFS just well but for some of them I get:

Error downloading object: Assets/VRITM/_Prefabs/SceneGraph/NetworkManager/DebugHUD/ConfigurationPanel/InputField.prefab (3a0c39040b397ab7120d427e019ad767b2bd6b91386856f9730507be1b59ad3c)

I can somehow restore the "copied" (newly cloned) project locally since I have exportet the whole Assets-Folder as unitypackage from my working local clone.

But after doing that, git still claims it is "up-to-date" so I can not commit/push again.

How can I repair those LFS tracked files on the remote repository (github)?

Since I have it all working fine on my local clone I guess there has to be some way to kind of "force" git-lfs to upload all files as I have them.


A second problem (This is solved now. See comments.)

Additionally I have two scripts which I renamed before the merge:
On the master it was

DebugHUDManager.cs
ConfigurationHUDManager.cs

But I renamed the classes and the files to

DebugHudManager.cs
ConfigurationHudManager.cs

so in my local (working) clone I have the later while when I clone newly I get the former files (..HUD..) and therefore a GameObject has only missing scripts attached. I can solve this by renaming only the files again. But this is not tracked in git also. It keeps saying "up-to-date".


This is my .gitattributes:

# Unity
*.cginc   text
*.cs      diff=csharp text
*.shader  text


# Unity YAML
*.anim               merge=unityyamlmerge eol=lf
*.asset              merge=unityyamlmerge eol=lf
*.controller         merge=unityyamlmerge eol=lf
*.mat                merge=unityyamlmerge eol=lf
*.meta               merge=unityyamlmerge eol=lf
*.physicsMaterial    merge=unityyamlmerge eol=lf
*.physicsMaterial2D  merge=unityyamlmerge eol=lf
*.prefab             merge=unityyamlmerge eol=lf
*.unity              merge=unityyamlmerge eol=lf


# Unity LFS
*.cubemap       filter=lfs diff=lfs merge=lfs -text
*.unitypackage  filter=lfs diff=lfs merge=lfs -text


# Image
*.ai    filter=lfs diff=lfs merge=lfs -text
*.apng  filter=lfs diff=lfs merge=lfs -text
*.astc  filter=lfs diff=lfs merge=lfs -text
*.bmp   filter=lfs diff=lfs merge=lfs -text
*.dds   filter=lfs diff=lfs merge=lfs -text
*.eps   filter=lfs diff=lfs merge=lfs -text
*.exr   filter=lfs diff=lfs merge=lfs -text
*.gif   filter=lfs diff=lfs merge=lfs -text
*.hdr   filter=lfs diff=lfs merge=lfs -text
*.jpeg  filter=lfs diff=lfs merge=lfs -text
*.jpg   filter=lfs diff=lfs merge=lfs -text
*.ktx   filter=lfs diff=lfs merge=lfs -text
*.png   filter=lfs diff=lfs merge=lfs -text
*.psd   filter=lfs diff=lfs merge=lfs -text
*.pvr   filter=lfs diff=lfs merge=lfs -text
*.svg   filter=lfs diff=lfs merge=lfs -text
*.svgz  filter=lfs diff=lfs merge=lfs -text
*.tga   filter=lfs diff=lfs merge=lfs -text
*.tif   filter=lfs diff=lfs merge=lfs -text
*.tiff  filter=lfs diff=lfs merge=lfs -text
*.webm  filter=lfs diff=lfs merge=lfs -text
*.webp  filter=lfs diff=lfs merge=lfs -text


# Audio
*.aif   filter=lfs diff=lfs merge=lfs -text
*.m4a   filter=lfs diff=lfs merge=lfs -text
*.mp3   filter=lfs diff=lfs merge=lfs -text
*.ogg   filter=lfs diff=lfs merge=lfs -text
*.wav   filter=lfs diff=lfs merge=lfs -text


# Video
*.asf   filter=lfs diff=lfs merge=lfs -text
*.avi   filter=lfs diff=lfs merge=lfs -text
*.flv   filter=lfs diff=lfs merge=lfs -text
*.mov   filter=lfs diff=lfs merge=lfs -text
*.mp4   filter=lfs diff=lfs merge=lfs -text
*.mpeg  filter=lfs diff=lfs merge=lfs -text
*.mpg   filter=lfs diff=lfs merge=lfs -text
*.ogv   filter=lfs diff=lfs merge=lfs -text
*.wmv   filter=lfs diff=lfs merge=lfs -text


# 3D Object
*.blend  filter=lfs diff=lfs merge=lfs -text
*.dxf    filter=lfs diff=lfs merge=lfs -text
*.fbx    filter=lfs diff=lfs merge=lfs -text
*.lxo    filter=lfs diff=lfs merge=lfs -text
*.ma     filter=lfs diff=lfs merge=lfs -text
*.max    filter=lfs diff=lfs merge=lfs -text
*.mb     filter=lfs diff=lfs merge=lfs -text
*.obj    filter=lfs diff=lfs merge=lfs -text


# Compressed Archive
*.7z   filter=lfs diff=lfs merge=lfs -text
*.bz2  filter=lfs diff=lfs merge=lfs -text
*.gz   filter=lfs diff=lfs merge=lfs -text
*.rar  filter=lfs diff=lfs merge=lfs -text
*.tar  filter=lfs diff=lfs merge=lfs -text
*.zip  filter=lfs diff=lfs merge=lfs -text


# Compiled Dynamic Library
*.dll  filter=lfs diff=lfs merge=lfs -text
*.pdb  filter=lfs diff=lfs merge=lfs -text
*.so   filter=lfs diff=lfs merge=lfs -text


# Compiled Static Library
*.a            filter=lfs diff=lfs merge=lfs -text
*.la           filter=lfs diff=lfs merge=lfs -text
*.lai          filter=lfs diff=lfs merge=lfs -text
*.lib          filter=lfs diff=lfs merge=lfs -text
*.llblgenproj  filter=lfs diff=lfs merge=lfs -text


# Font
*.otf  filter=lfs diff=lfs merge=lfs -text
*.ttf  filter=lfs diff=lfs merge=lfs -text


# Executable/Installer
*.apk  filter=lfs diff=lfs merge=lfs -text
*.exe  filter=lfs diff=lfs merge=lfs -text


# Documents
*.pdf  filter=lfs diff=lfs merge=lfs -text


# Other
*.reason  filter=lfs diff=lfs merge=lfs -text
*.rns filter=lfs diff=lfs merge=lfs -text

Further Notes

  • Problems started after some huge merging.

  • I did not have the Smart-Merging of Unity with UnityYamlMerge.exe activated. (I added this now.)

  • All of the missing files are of the types .prefab and .unity. And all of them seem to be part of my latest commits before the merge. But other .prefab files are downloaded fine.

  • Also the size seems not to matter because most of them have like 10Kb while some .prefab files which are downloaded well have e.g. 1,9Mb.

  • Asset Serialization-Mode = Force Text

  • I just made another test commit with just a new .prefab file. That works just fine. The only thing not working are those specific .prefab files which were added/changed by the merge.

How can I rescue this project? o.O

UPDATE:
Meanwhile I made a new repository and copied the files (ofcourse excluding the .git folder) from my working local clone in. But ofcourse the history in the new repository is gone. But atleast we can go on working together.

like image 609
derHugo Avatar asked Jan 05 '18 08:01

derHugo


1 Answers

I know you have already solved your merge issue but I wanted to document my fix for the same problem. That is, where I tried to merge LFS-tracked .prefabs into master and the files were either corrupted or mis-linked and either way just wouldn't load in the Unity project after the merge.

After seeing your .gitattributes file above I realized the issue was that SmartMerge (UnityYAMLMerge) wasn't handling the merge and so of course the files weren't going to merge. Here's what I did:

First, I reset master and then confirmed everything still worked in Unity

git reset --hard origin/master

Second, I updated my .gitattributes file using settings similar to yours, effectively moving all .prefabs out of LFS so they could be handled by UnityYAMLMerge.

enter image description here

Third, I committed the change to master.

With that done, switched to the branch I wished to merge and performed the same tasks all over again, which also moved the updated versions of the .prefabs to be handled by UnityYAMLMerge.

Finally, back in the master I attempted to merge the updated branch and all the .prefabs were merged happily (thanks to a few reviews in Atom which I highly recommend for the external tool) and without a single error.

EDIT: Adding this setting to .gitattributes does not guarantee that the .prefab will move out of LFS—it only happens once you edit the .prefab. This can be a pain when you are trying to merge a branch that still points to the .prefab in LFS which breaks references in Unity. For this, I copied the text of the asset over the original with the LFS reference and relinked in Unity.

atom

like image 111
ow3n Avatar answered Nov 18 '22 23:11

ow3n