如何仅从Git的根文件夹中排除文件 [英] How to exclude file only from root folder in Git

查看:102
本文介绍了如何仅从Git的根文件夹中排除文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道使用 .gitignore 文件来排除一些正在添加的文件,但我有几个 config.php 源代码树中的文件,我需要排除只有一个,位于根,而其他人保持在修订控制。

I am aware of using .gitignore file to exclude some files being added, but I have several config.php files in source tree and I need to exclude only one, located in the root while other keep under revision control.

我应该写入 .gitignore 才能做到这一点吗?

What I should write into .gitignore to make this happen?

推荐答案

文档: p>

From the documentation:


如果模式不包含斜杠/,git会将其视为shell glob模式,并检查与相对于该位置的路径名的匹配.gitignore文件(相对于工作树的顶层,如果不是.gitignore文件的话)。

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).

一个前导斜杠匹配路径名的开头。例如,/*.c匹配cat-file.c,但不匹配mozilla-sha1 / sha1.c。

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的根文件夹中排除文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆