我知道使用.gitignore文件排除一些正在添加的文件,但我有几个config.php文件在源树中,我只需要排除一个,位于根,而其他保持在修订控制下。
我应该在。gitignore里写什么来实现这个?
我知道使用.gitignore文件排除一些正在添加的文件,但我有几个config.php文件在源树中,我只需要排除一个,位于根,而其他保持在修订控制下。
我应该在。gitignore里写什么来实现这个?
从文档中可以看到:
如果模式不包含斜杠/,git将其视为shell glob模式,并根据相对于.gitignore文件位置的路径名(如果不是来自.gitignore文件,则相对于工作树的顶层)检查匹配。 前导斜杠匹配路径名的开头。例如,“/*.c”匹配“cat-file.c”,但不匹配“mozilla-sha1/sha1.c”。
所以你应该在你的根目录.gitignore后面加上下面这行代码:
/config.php
如果上面的方法不适合你,试试下面的方法:
#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
旧版本的git要求您首先定义一个忽略模式,然后立即(在下一行)定义排除。[在1.9.3版本上测试(Apple Git-50)]
/config.php
!/*/config.php
后续版本只需要以下[在版本2.2.1上测试]
/config.php
一个wordpress站点的例子,但基本上忽略所有内容,然后添加异常从!包括什么
# Ignore everything in the root except the "wp-content" directory.
/*
!.gitignore
!wp-content/
!wp-config.php
#
# # Ignore everything in the "wp-content" directory, except the "plugins"
# # and "themes" directories.
wp-content/*
!wp-content/plugins/
!wp-content/themes/
#
# # Ignore everything in the "plugins" directory, except the plugins you
# # specify (see the commented-out examples for hints on how to do this.)
wp-content/plugins/*
# # !wp-content/plugins/my-single-file-plugin.php
# # !wp-content/plugins/my-directory-plugin/
#
# # Ignore everything in the "themes" directory, except the themes you
# # specify (see the commented-out example for a hint on how to do this.)
wp-content/themes/*
!wp-content/themes/twentyeleven/