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

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

问题描述

由于外部奇怪的限制,我无法修改我的存储库的.gitignore。有没有办法忽略修改.gitignore以外的文件和目录?即使它是一个像全局配置一样的全局解决方案,将会应用到我所有的仓库中。

gitignore ,在Git考虑的不同忽略模式来源中有一个优先顺序:


  • 模式从命令行读取支持它们的命令。 .gitignore文件与路径相同的目录或任何父目录中,高层文件中的模式(直到根目录)被低层文件中的模式覆盖到包含该文件的目录。

  • $ GIT_DIR / info / exclude 读取的模式。

  • 指定的配置变量 core.excludesfile



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


  • 它们不会被复制到远程存储库

  • 它们可以让他们的模式被其他来源重写



(另见 SO问题






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



但是,当您签出另一个分支或何时你 git pull ,那么忽略状态可能会被重置。因此,另一个选项:
$ b $ ul

  • git update-index --skip-worktree ;请参阅:




  • Git - 假定 - 不变'和'<$之间的区别c $ c> skip-worktree '


    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.

    解决方案

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

    • 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:

    • they are not replicated for a distant repository
    • they can have their patterns overridden by the other sources

    (See also this SO question)


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

    However, when you checkout another branch or when you git pull, that "ignore" status might be reset. Hence the other option:

    The difference between the two is explained in "Git - Difference Between 'assume-unchanged' and 'skip-worktree'".

    这篇关于如何在不使用.gitignore的情况下让Git忽略文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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