git .gitignore 中的异常
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2415873/
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
Exceptions in .gitignore
提问by pistacchio
How can I add an exception to .gitignore, like "ignore all the .dll files BUTmyfile.dll"?
如何向 .gitignore 添加异常,例如“忽略所有 .dll 文件但myfile.dll”?
回答by Ben James
Use !
to negate the pattern:
使用!
否定的模式:
*.dll
!myfile.dll
回答by cubuspl42
If you want to ignore whole folder, except some specific files, then write:
如果你想忽略整个文件夹,除了一些特定的文件,然后写:
MyFolder/*
!MyFolder/CoolFile.txt
This won'twork:
这将不工作:
MyFolder/
!MyFolder/CoolFile.txt
回答by Anver Sadhat
You can also ignore folderslike
您也可以忽略文件夹,如
!src/main/resources/archetype-resources/**/*
you can also ignore nested folder with patternslike
你也可以忽略带有图案的嵌套文件夹一样
!**/src/test/resources/**/*
回答by kamayd
You can have several .gitignore
files working together in a hierarchical manner to achieve your goal.
At the root level you may have:
您可以将多个.gitignore
文件以分层方式协同工作以实现您的目标。在根级别,您可能拥有:
root
根
*.dll
inside the folder having the myfile.dll
you can add another .gitignore
file like so:
在文件夹中,myfile.dll
您可以添加另一个.gitignore
文件,如下所示:
root/lib/folderwithMyFiledll
root/lib/folderwithMyFiledll
!myfile.dll
more info here
更多信息在这里
An optional prefix "!" which negates the pattern; any matching file excluded by a previous pattern will become included again. Put a backslash ("\") in front of the first "!" for patterns that begin with a literal "!", for example, "!important!.txt". It is possible to re-include a file if a parent directory of that file is excluded if certain conditions are met. See section NOTES for detail.
一个可选的前缀“!” 这否定了模式;任何被先前模式排除的匹配文件将再次包含在内。在第一个“!”前面放一个反斜杠(“\”)对于以文字“!”开头的模式,例如,“!important!.txt”。如果满足某些条件,则可以重新包含文件,如果该文件的父目录被排除在外。有关详细信息,请参阅注释部分。
回答by Robbiegod
I did this because I have a folder called /modules
that I want to ignore, except everything in the /modules/custom
folder. This worked for me. Now my custom modules will get synced to GitHub.
我这样做是因为我有一个名为/modules
我想忽略的/modules/custom
文件夹,文件夹中的所有内容除外。这对我有用。现在我的自定义模块将同步到 GitHub。
/modules/*
!/modules/custom/