我知道使用 .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/