我知道使用.gitignore
文件来排除一些正在添加的文件,但是我config.php
在源代码树中有几个文件,我只需要排除一个位于根目录中的文件,而其他文件则处于修订控制之下。
我应该写什么.gitignore
来实现这一点?
从文档中:
如果模式不包含斜杠 /,git 将其视为 shell glob 模式并检查相对于 .gitignore 文件位置的路径名是否匹配(如果不是来自 .gitignore,则相对于工作树的顶层文件)。
前导斜杠匹配路径名的开头。例如,“/*.c”匹配“cat-file.c”但不匹配“mozilla-sha1/sha1.c”。
因此,您应该将以下行添加到您的 root .gitignore
:
/config.php
使用/config.php
.
旧版本的 git 要求您首先定义一个忽略模式并立即(在下一行)定义排除项。[在版本 1.9.3 (Apple Git-50) 上测试]
/config.php
!/*/config.php
更高版本只需要以下 [在 2.2.1 版本上测试]
/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
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/