Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
.gitattributes for Unity3D with git-lfs
## Unity ##
*.cs diff=csharp text
*.cginc text
*.shader text
*.mat merge=unityyamlmerge eol=lf
*.anim merge=unityyamlmerge eol=lf
*.unity merge=unityyamlmerge eol=lf
*.prefab merge=unityyamlmerge eol=lf
*.physicsMaterial2D merge=unityyamlmerge eol=lf
*.physicMaterial merge=unityyamlmerge eol=lf
*.asset merge=unityyamlmerge eol=lf
*.meta merge=unityyamlmerge eol=lf
*.controller merge=unityyamlmerge eol=lf
## git-lfs ##
#Image
*.jpg filter=lfs diff=lfs merge=lfs -text
*.jpeg filter=lfs diff=lfs merge=lfs -text
*.png filter=lfs diff=lfs merge=lfs -text
*.gif filter=lfs diff=lfs merge=lfs -text
*.psd filter=lfs diff=lfs merge=lfs -text
*.ai filter=lfs diff=lfs merge=lfs -text
#Audio
*.mp3 filter=lfs diff=lfs merge=lfs -text
*.wav filter=lfs diff=lfs merge=lfs -text
*.ogg filter=lfs diff=lfs merge=lfs -text
#Video
*.mp4 filter=lfs diff=lfs merge=lfs -text
*.mov filter=lfs diff=lfs merge=lfs -text
#3D Object
*.FBX filter=lfs diff=lfs merge=lfs -text
*.fbx filter=lfs diff=lfs merge=lfs -text
*.blend filter=lfs diff=lfs merge=lfs -text
*.obj filter=lfs diff=lfs merge=lfs -text
#ETC
*.a filter=lfs diff=lfs merge=lfs -text
*.exr filter=lfs diff=lfs merge=lfs -text
*.tga filter=lfs diff=lfs merge=lfs -text
*.pdf filter=lfs diff=lfs merge=lfs -text
*.zip filter=lfs diff=lfs merge=lfs -text
*.dll filter=lfs diff=lfs merge=lfs -text
*.unitypackage filter=lfs diff=lfs merge=lfs -text
*.aif filter=lfs diff=lfs merge=lfs -text
*.ttf filter=lfs diff=lfs merge=lfs -text
*.rns filter=lfs diff=lfs merge=lfs -text
*.reason filter=lfs diff=lfs merge=lfs -text
*.lxo filter=lfs diff=lfs merge=lfs -text
@jwvanderbeck
Copy link

jwvanderbeck commented Mar 30, 2019

I have been digging into this as well and wanted to point out that Unity's documentation for YAMLMerge indicates it should be used only for two types of files: .unity and .prefab

https://docs.unity3d.com/Manual/SmartMerge.html

@NPatch
Copy link

NPatch commented Jun 7, 2019

Also what's the point of treating 3D objects/Video/Audio/Image as text? They are all binary. Ofc there are in some cases, ascii versions(FBX probably has one, OBJ is by default but there's a binary version as well, though almost no one uses it).

@nemotoo
Copy link
Author

nemotoo commented Jun 7, 2019

"-text" means non text : https://git-scm.com/docs/gitattributes

@NPatch
Copy link

NPatch commented Jun 7, 2019

@nemotoo My bad..thx!

@dorkbot
Copy link

dorkbot commented Aug 9, 2019

thanks for this. How would I use this with Unity assetbundles?

@nemotoo
Copy link
Author

nemotoo commented Aug 10, 2019

@dorkbot Unfortunately, I have no idea that how to manage assetbundles with git-lfs.
By the way, Unity team released new asset manage system.
I recommend this if you want to manage assets with git-lfs.
https://blogs.unity3d.com/2019/07/15/addressable-asset-system/

@zloop1982
Copy link

zloop1982 commented Oct 22, 2020

@nemotoo I see you use merge=unityyamlmerge to let git use unityyamlmerge for one type of files, How to let git know the unityyamlmerge tool?
how to config unityyamlmerge in .gitconfig file?

I like your way to set unityyamlmerge for specified files.
but this setting in .gitconfig file:
[merge]
tool = unityyamlmerge
I'm afraid that may let git always use unityyamlmerge for everything.

@Chefty
Copy link

Chefty commented Jan 20, 2021

I agree with @evitolins what about tracking .unity and .asset with LFS?
From what I read here it will only be handled by unity yaml "smart merge"?

I have very large scenes over 100mb and Github is complaining about it. Without talking about lighting datas...
I added these two lines at the end of my .gitattributes:

# Scenes
*.unity lfs
[Aa]ssets/[Ss]cenes/*.assets lfs

But now will the yaml "smart merge" still work?

@upscalebaby
Copy link

upscalebaby commented Oct 6, 2021

I like this one, I'd add HDR image support as well:

*.hdr filter=lfs diff=lfs merge=lfs -text

@benkoadam
Copy link

benkoadam commented Dec 30, 2021

Since you are using yamalMerge for *.unity, lets say that you have just created a scene with more than 200 MB in size. How will you push it ? Did you increase your git push limit too ?

@Hoodad
Copy link

Hoodad commented Jan 27, 2022

To prevent LightingData.asset to become corrupted I highly recommend to treat it like a binary file. When working we have had multiple occureneces where the LightingData.asset ended up corrupt when pushed through LFS due to the unityyamlmerge

LightingData.asset filter=lfs diff=lfs merge=lfs -text

@fkkcloud
Copy link

fkkcloud commented Apr 14, 2022

with #*.wav filter=lfs diff=lfs merge=lfs -text, when I merge other branches that has changed .wav files, I am getting .wav files "dirty" and listed in the changelist (it is not the conflict btw) every time. if I remove "filter=lfs", it works fine. any ideas?

@omundy
Copy link

omundy commented Apr 21, 2022

Thanks for this. Consider adding .psb files (along with PSDs)

@SuleimanAbdullah
Copy link

SuleimanAbdullah commented Jun 23, 2022

Thanks, @Hoodad I have spent weeks to solve this but light data make push large file failed I follow your recommendation and the push worked thanks again you save my day

@Breanzy
Copy link

Breanzy commented Jun 23, 2022

Thanks for this ^^

@Begounet
Copy link

Begounet commented Nov 3, 2022

Months later, got the same issue, because based my .gitattributes on this. Thank you @Hoodad! Should really consider adding this to the file.

@jwvanderbeck
Copy link

jwvanderbeck commented Nov 3, 2022

As I had pointed out way above, the yaml merge tool is NOT supposed to be used on .asset files. Only .unity and .prefab

@SuleimanAbdullah
Copy link

SuleimanAbdullah commented Nov 4, 2022

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