我知道使用.gitignore文件来排除一些正在添加的文件,但我config.php在源代码树中有几个文件,我只需要排除一个位于根目录中,而其他文件保持在版本控制之下.
我应该写什么.gitignore来实现这一目标?
Man*_*dan 537
从文档:
如果模式不包含斜杠/,git将其视为shell glob模式,并检查相对于.gitignore文件位置的路径名的匹配(相对于工作树的顶层,如果不是来自.gitignore)文件).
前导斜杠与路径名的开头匹配.例如,"/*.c"匹配"cat-file.c"但不匹配"mozilla-sha1/sha1.c".
所以你应该在你的root中添加以下行.gitignore:
/config.php
Run Code Online (Sandbox Code Playgroud)
ken*_*pdx 26
旧版本的git需要先定义一个忽略模式,然后立即(在下一行)定义排除.[在1.9.3版本(Apple Git-50)上测试]
/config.php
!/*/config.php
Run Code Online (Sandbox Code Playgroud)
更高版本仅需要以下[在2.2.1版本上测试]
/config.php
Run Code Online (Sandbox Code Playgroud)
dru*_*gan 15
如果上述解决方案不适合您,请尝试以下方法:
#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
Run Code Online (Sandbox Code Playgroud)