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
@nickcottrell
Copy link

nickcottrell commented Nov 20, 2017

thanks!

@FullStackForger
Copy link

FullStackForger commented Jan 26, 2018

Thanks @jason-yak. Here is fork with updated physics -> physic along with some other configuration following this guide.

@NPatch
Copy link

NPatch commented Mar 22, 2018

I also stumbled on the terrain issue. Problem is that most .asset files in Unity are YAML but TerrainData is the only thing I know of that is binary even if you Force Text serialization. Couldn't Unity just use a different extension if it was a special case?! Oh well.

@timdhoffmann
Copy link

timdhoffmann commented Apr 9, 2018

@NPatch I was asking myself the same thing. Might be best to just stick to tracking Terrain assets in regular git?

@40detectives
Copy link

40detectives commented Apr 24, 2018

@NPatch @hoffmannprojects
I can think of two solutions:

1. If only the terrain files are the .asset that are always binary ones, which I'm not 100% sure right now (after a quick search I found a couple more binaries but were on directories like Library that are not meant to be versioned), you can save all terrains in a specific path like Assets/Terrains/** (or similar). And add it to your .gitattribute file right in this order:

*.asset merge=unityyamlmerge eol=lf
/Assets/Terrains/*.asset filter=lfs diff=lfs merge=lfs -text
#only if subfolders with terrains exist:
/Assets/Terrains/**/*.asset filter=lfs diff=lfs merge=lfs -text

2. Let git guess the type of file with:

*.asset merge=unityyamlmerge text=auto

I will probably go for the first option (if you can afford that folder structure) since it's the more flexible.

@jojoblaze
Copy link

jojoblaze commented Aug 5, 2018

I added .exr too. Sounds correct?

@lopespm
Copy link

lopespm commented Aug 23, 2018

LightingData.asset seems to be always binary. This should also be added as well I believe?

 LightingData.asset binary

@Dreaddisk
Copy link

Dreaddisk commented Sep 23, 2018

Noob here, is this a better version of the Unity.gitignore or a different file?

@debuggins
Copy link

debuggins commented Sep 27, 2018

@Dreaddisk This file is for use with Git LFS

@jacobschellenberg
Copy link

jacobschellenberg commented Oct 4, 2018

I see you're using:

*.asset merge=unityyamlmerge eol=lf

for all .asset files. But what I'm finding is that things like, /ProjectSettings/* is text, like TagsManager.asset and should be able to merge by line. So yeah, we don't want those in LFS.

On the other hand, Unity decided to use .asset for other things too, like meshes, materials, and others. Some of which are upwards of 25mb. Some of which are text (mesh/material), but others that are binary.

Is there a way to specify, if binary use lfs? Or do you really think it's okay for all .asset files to not use LFS?

@40detectives
Copy link

40detectives commented Oct 8, 2018

I see you're using:

*.asset merge=unityyamlmerge eol=lf

for all .asset files. But what I'm finding is that things like, /ProjectSettings/* is text, like TagsManager.asset and should be able to merge by line. So yeah, we don't want those in LFS.

On the other hand, Unity decided to use .asset for other things too, like meshes, materials, and others. Some of which are upwards of 25mb. Some of which are text (mesh/material), but others that are binary.

Is there a way to specify, if binary use lfs? Or do you really think it's okay for all .asset files to not use LFS?

Check my previous message just a little bit above in the page.

I would probably go with the option 1, just because I do not really trust the ability of git to determine that. So you would like to identify the "*.assets" that are binaries and make some rules just for them. The most commons are terrains, not sure of any others.

@Domvel
Copy link

Domvel commented Oct 16, 2018

Some *.asset files are binary, others text. I also have a hybrid (text / binary) asset file with a size of 180 MB. How to handle it in .gitattributes?
*.asset filter=lfs diff=lfs merge=lfs -text?

@douglassophies
Copy link

douglassophies commented Nov 25, 2018

I have been having issues with asset files as well. Is there an updated version of this that has the rules for the common binary and text .asset types? It would be good to have one place to go for a Unity Git LFS file instead of reinventing the wheel each time.

@bitinn
Copy link

bitinn commented Dec 9, 2018

For people looking at limiting binary *.asset file size, I got a solution for you.

https://stackoverflow.com/a/53692461/1677057

@FrankNine
Copy link

FrankNine commented Mar 27, 2019

Looked into line ending of files with .asset extension in Force Text mode

crlf

  • .asset files under ProjectSettings

lf

  • Tile set config

Still binary with Force Text

  • Lighting Data
  • Terrain Data

2 cents: Leave .asset alone

@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 ^^

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