Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignoring folder meta files on version control

Unity creates and deletes meta files for folders inside the Asset folder.

That can create an annoying situation when using version control (that you can skip and go to the questions): someone creates a folder of files that will be ignored but forget to ignore the folder's meta file. Unity creates the meta file and this person adds the meta to version control. Another person gets the changesets and, since they don't have the folder, their Unity deletes the meta file and they remove the meta file from version control. Not everyone in the team understand this, so the process is perpetuated in a loop from hell.

Surprisingly this happens all the time. So, two questions:

  1. Is it important to version folder meta files?
  2. Is there a way to automatically ignore folder meta files - particularly on git or mercurial?
like image 791
Roberto Avatar asked Oct 03 '13 05:10

Roberto


People also ask

Do you need to commit meta files unity?

Yes. Unity's . meta files form a critical part of your project and hence should be committed to your Version Control System.

What are unity meta files?

A . meta file is created. The relationship between the Assets Folder in your Unity Project on your computer, and the Project Window within Unity. You'll notice in the image above that there are . meta files listed in the file system for each asset and folder created within the Assets folder.

What does Meta File do?

A metafile is a file containing information that describes or specifies another file. Microsoft uses this term for its Windows Metafile (WMF) format.


2 Answers

The Unity docs say:

When creating new assets, make sure both the asset itself and the associated .meta file is added to version control.

For me this is reason enough to put them under version control. I see two approaches to solve the problem:

  • Organisational: Set up a naming convention for local folders like starting with "_". But we all know that this won't work ;-)
  • Install a client side pre-commit hook on all machines. I haven't done this yet but it seems promising.

I just played around with the different git commands, the following could be useful: The git hook script shoud first check if .gitignore has changed by:

git diff-index --cached --name-only HEAD | grep ".gitignore" 

Print out directory names of all newly added lines in .gitignore if they are located under the Assets folder:

git diff --cached --word-diff=plain .gitignore | grep -o -e "{+\/.*\/Assets\/.*+}" | cut -d + -f 2 

Update

I just wrote such a pre-commit hook :-) See the GitHub repository git-pre-commit-hook-unity-assets for code and my blog posting about it for more details.

like image 141
Kay Avatar answered Sep 24 '22 17:09

Kay


Add this to .gitignore

#Ignore all .meta file *.meta #But not source file with postfix. which is everything but a folder !*.*.meta 

This will ignore file without postfix. But that shouldn't hurt.

like image 24
Guo Lieene Avatar answered Sep 24 '22 17:09

Guo Lieene