git - 如何仅从 Git 的根文件夹中排除文件

标签 git gitignore

我知道使用 .gitignore 文件来排除一些正在添加的文件,但是我在源代码树中有几个 config.php 文件,我只需要排除一个, 位于根目录中,而其他的则处于版本控制之下。

我应该在 .gitignore 中写入什么来实现这一点?

最佳答案

来自documentation :

If the pattern does not contain a slash /, git treats it as a shell glob pattern and checks for a match against the pathname relative to the location of the .gitignore file (relative to the toplevel of the work tree if not from a .gitignore file).

A leading slash matches the beginning of the pathname. For example, "/*.c" matches "cat-file.c" but not "mozilla-sha1/sha1.c".

因此,您应该将以下行添加到您的根 .gitignore:

/config.php

关于git - 如何仅从 Git 的根文件夹中排除文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3637660/

相关文章:

git - 如何在不使用 git-stash 的情况下保存正在进行的工作?

git - 从一个 repo git clone 并将 origin 设置为另一个是 "safe"吗?

git - 忽略已经提交到 Git 存储库的文件

git - 为什么 .gitignore 不忽略我的文件?

git - 如何用主要版本替换 Go 模块到 fork @ master

git - 使用 "git commit -am"的初始提交失败并在推送到 GitHub 时导致错误

svn - 在使用 git 和 git-svn 桥接器时,如何指示要在 svn 中忽略的文件?

iphone - iPhone (Xcode) 项目的 .gitignore 的 'standard' 内容是什么?

git - 让 Git 日志统计有自己的专栏?

git - 应该忽略 bower_components 吗?