git .gitignore 文件的反面?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6011521/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 10:55:54  来源:igfitidea点击:

opposite of .gitignore file?

git

提问by morpheus

Possible Duplicate:
Make .gitignore ignore everything except a few files

可能的重复:
使 .gitignore 忽略除少数文件之外的所有内容

Is it possible to let git ignore all files by default, unless specified in a special file?

是否可以让 git 默认忽略所有文件,除非在特殊文件中指定?

回答by sehe

You can include !-lines to whitelist files: a .gitignore with:

您可以将 !-lines 包含到白名单文件中:一个 .gitignore 与:

*
!included/

will exclude all, but the 'included/' directory

将排除所有,但 'included/' 目录

Note that if you want files matching a pattern to be un-ignored, in subdirectories, you will need to prevent the containing directories from getting ignored too. This should not pose a large problem, since git doesn't actually track directories, only files (identified by a repository path).

请注意,如果您希望不忽略与模式匹配的文件,则在子目录中,您还需要防止包含的目录也被忽略。这应该不会造成大问题,因为 git 实际上并不跟踪目录,只跟踪文件(由存储库路径标识)。

Example:

例子:

*
!*/
!SOURCES

will ignore everything, except SOURCESin subdirectories.

将忽略所有内容,除了SOURCES子目录。

回答by tamasd

You can use .gitignore for that.

你可以使用 .gitignore 。

*
!file0.txt
!file1.txt

In a case where you interested in file0.txt and file1.txt.

如果您对 file0.txt 和 file1.txt 感兴趣。