我知道使用.gitignore文件来排除一些正在添加的文件,但我在源代码树中有几个config.php文件,我只需要排除一个位于根目录中,而其他文件保持在版本控制之下。
我应该写什么.gitignore来实现这一目标?
#1楼
如果上述解决方案不适合您,请尝试以下方法:
#1.1 Do NOT ignore file pattern in any subdirectory
!*/config.php
#1.2 ...only ignore it in the current directory
/config.php
##########################
# 2.1 Ignore file pattern everywhere
config.php
# 2.2 ...but NOT in the current directory
!/config.php
#2楼
旧版本的git需要先定义一个忽略模式,然后立即(在下一行)定义排除。 [在1.9.3版本(Apple Git-50)上测试]
/config.php
!/*/config.php
更高版本仅需要以下[在2.2.1版本上测试]
/config.php
#3楼
使用/config.php 。
#4楼
从文档 :
如果模式不包含斜杠/,git将其视为shell glob模式,并检查相对于.gitignore文件位置的路径名的匹配(相对于工作树的顶层,如果不是来自.gitignore)文件)。
前导斜杠与路径名的开头匹配。 例如,“/ *。c”匹配“cat-file.c”但不匹配“mozilla-sha1 / sha1.c”。
所以你应该在你的root .gitignore添加以下行:
/config.php
来源:oschina
链接:https://my.oschina.net/stackoom/blog/3182805