如何在不使用 .gitignore 的情况下让 Git 忽略文件? [英] How do you make Git ignore files without using .gitignore?

查看:29
本文介绍了如何在不使用 .gitignore 的情况下让 Git 忽略文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于外部奇怪的限制,我无法修改存储库的 .gitignore.除了修改 .gitignore 之外,有没有办法忽略文件​​和目录?即使它是一个全局解决方案,例如将应用于我所有存储库的全局配置.

Due to external weird constraints I cannot modify the .gitignore of my repository. Is there a way to ignore files and directories other than modifying a .gitignore? Even if it is a global solution like a global configuration that will be applied to all my repositories.

推荐答案

不要忘记,根据 gitignore,在 Git 考虑的不同忽略模式源"中存在优先顺序:

Do not forget, according to gitignore, that there is an order of precedence in the different "ignore pattern sources" that Git consider:

  • 从命令行读取支持它们的命令的模式.
  • 从与路径相同的目录或任何父目录中的 .gitignore 文件中读取的模式,高级文件中的模式(直到根目录)被低级文件中的模式覆盖,直到包含文件.
  • $GIT_DIR/info/exclude 读取的模式.
  • 从配置变量 core.excludesfile 指定的文件中读取的模式.
  • Patterns read from the command line for those commands that support them.
  • Patterns read from a .gitignore file in the same directory as the path, or in any parent directory, with patterns in the higher level files (up to the root) being overridden by those in lower level files down to the directory containing the file.
  • Patterns read from $GIT_DIR/info/exclude.
  • Patterns read from the file specified by the configuration variable core.excludesfile.

最后两个可以解决您的问题,但是:

The last two can be a solution for your problem but:

  • 不会为远程存储库复制它们
  • 他们可以让其他来源覆盖他们的模式

(另见此 SO 问题)

另外两个解决方案涉及更新索引(git update-index):

The other two solutions involve updating the index (git update-index):

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