Ignoring folder meta files on version control

后端 未结 3 1193
不知归路
不知归路 2021-01-30 12:13

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 an

3条回答
  •  执笔经年
    2021-01-30 12:52

    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.

提交回复
热议问题