git gitignore 以及如何忽略通用目录名称及其内容
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3919812/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
gitignore and how to ignore a common directory name and its contents
提问by Matt Scheurich
I've been pulling out my hair researching the net and various docs about .gitignore files. I'm a bit of a n00b with Unix/Terminal (using Mac OS X) and I can't for the life of me figure out how to ignore a folder's contents (any kind of content, be it a file or another folder, no matter how deep it is).
我一直在研究有关 .gitignore 文件的网络和各种文档。我对 Unix/终端(使用 Mac OS X)有点像 n00b,我一生都无法弄清楚如何忽略文件夹的内容(任何类型的内容,无论是文件还是其他文件夹,不管它有多深)。
I'm working on a project that generates image files within a consistent file structure, except we're getting merge conflicts regarding user permissions. I'd like to ignore the folders that contain the generated images so we can avoid any further hair-pulling having to adjust permissions on a per-pull basis. I'm just having trouble getting the .gitignore file to work, so I need to figure out the right pattern for folder's content matching. I want it to be general enough in that it can easily encompass the whole site (so if any folder contains a particular folder name, it will ignore its contents).
我正在开发一个在一致的文件结构中生成图像文件的项目,除了我们遇到关于用户权限的合并冲突。我想忽略包含生成图像的文件夹,这样我们就可以避免任何进一步的麻烦,必须在每次拉取的基础上调整权限。我只是在让 .gitignore 文件工作时遇到问题,所以我需要找出文件夹内容匹配的正确模式。我希望它足够通用,因为它可以轻松包含整个站点(因此,如果任何文件夹包含特定文件夹名称,它将忽略其内容)。
I've tried:
我试过了:
# Images
resample/
resize/
min/
And...
和...
# Images
resample/*
resize/*
min/*
And...
和...
# Images
*/resample/*
*/resize/*
*/min/*
And many more combinations with unsatisfactory results. I never got the foldername/**/*
pattern to ever work either. Any help regarding this issue would be most appreciated!
还有更多的组合结果不尽人意。我也从来没有得到过这种foldername/**/*
模式。任何有关此问题的帮助将不胜感激!
回答by Matt Scheurich
Thanks to the previous posters for their help. After some further delving in, I discovered how to properly implement the new .gitignore
rules. The problem was that previously the images were being tracked so I had to remove the reference to the files within the .git/index
file, like so...
感谢以前的海报他们的帮助。经过深入研究,我发现了如何正确实施新.gitignore
规则。问题是以前正在跟踪图像,所以我不得不删除对文件中文件的引用.git/index
,就像这样......
// Remove all tracked files from the index
// (doesn't remove the file, just the reference)
git rm -r --cached .
// Add all the files again
// (files and folders specified by .gitignore aren't added to the index)
git add .
// Commit to save changes
git commit -am "gitignore update"
回答by kevpie
You're looking for gitignore
您正在寻找 gitignore
A gitignore file specifies intentionally untracked files that git should ignore. Note that all the gitignore files really concern only files that are not already tracked by git;
gitignore 文件指定了 git 应该忽略的有意未跟踪的文件。请注意,所有 gitignore 文件实际上只涉及 git 尚未跟踪的文件;
If your file or folder is in the repository it must be deleted from the repository for it to be ignorable.
如果您的文件或文件夹在存储库中,则必须将其从存储库中删除才能被忽略。
Also watch out for case sensitivity in your patterns.
还要注意模式中的区分大小写。
Your first list should work assuming those folders are not under version control currently.
假设这些文件夹当前不受版本控制,您的第一个列表应该可以工作。
# Images
resample/
resize/
min/