在版本控制上忽略文件夹元文件 [英] Ignoring folder meta files on version control

查看:94
本文介绍了在版本控制上忽略文件夹元文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Unity在资源文件夹内创建和删除文件夹的元文件。



这会在使用版本控制时造成恼人的情况您可以跳过并转到问题):有人创建了一个文件夹,将被忽略,但忘记忽略该文件夹的元文件。 Unity创建元文件,并将该元素添加到版本控制中。另一个人获得变更集,并且由于他没有该文件夹,他的Unity删除了元文件,他从版本控制中删除元文件。并非团队中的每个人都明白这一点,所以这个过程是从地狱循环中延续下来的。



奇怪的是,这种情况一直发生。因此,有两个问题:


  1. 版本文件夹元文件是否很重要?

  2. 有没有办法自动忽略文件夹元文件 - 尤其是在git或mercurial上?


解决方案

Unity文档说:


在创建新资产时,请确保资产本身和关联的.meta文件都已添加到版本控制中。

对我来说,这足以让它们置于版本控制之下。我看到了两种解决问题的方法:


  • 组织:为本地文件夹设置命名约定,例如以_开头。但是我们都知道这是行不通的 - )

  • 安装客户端预先挂钩。我还没有这样做,但它似乎很有前途。



我刚刚玩过各种不同的git命令,以下内容可能会有用:
git钩子脚本首先检查如果.gitignore改变了:

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

如果找到位于.gitignore中的所有新添加行的目录名称在Assets文件夹下:

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






更新

我刚刚写了这样一个预先提交的钩子:-)请参阅GitHub存储库 git-pre-commit-hook-unity-assets 的代码和我的博客张贴关于它的更多细节。


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 the person adds the meta to version control. Another person gets the changesets and, since he doesn't have the folder, his Unity delete the meta file and he removes 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?

解决方案

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.

这篇关于在版本控制上忽略文件夹元文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆