如何始终忽略git上的文件(包含特定行)? [英] How to always ignore a file (containing a specific line) on git?

查看:101
本文介绍了如何始终忽略git上的文件(包含特定行)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我公司的每个项目中,我们都有一个配置文件config.xml,其中包含不应公开的文本super_confidential_info.解决方案是在提交之前删除super_confidential_info.

In every project of my company, we have a configuration file config.xmlwhich contains the text super_confidential_info which should not be exposed. The solution is to remove super_confidential_infobefore any commit.

所以我要做的是避免在包含super_confidential_info的同时意外提交config.xml.这不仅适用于我当前的项目,而且可能适用于所有将来的项目.有什么办法设置git来做到这一点?

So what I want to do is to avoid to accidentally commit config.xml while containing super_confidential_info. This is not only true for my current projects, but possibly also all the future projects. Is there any way to setup git to do this?

推荐答案

Git的忽略系统基于不支持任何条件的基本.gitignore文件(和某些配置).因此,如果包含特定内容,则无法忽略文件​​.

Git's ignoring system based on basic .gitignore files (and some configurations) which do not support any kind of conditions. So it's not possible to ignore a file if contains specific content.

这是您可以做的:

通过使用预提交钩子,您可以使用 sed 搜索super_confidential_info,如果文件包含该文件,则可以取消暂存文件.这样,您就不会意外提交.

By using pre-commit hook you can search super_confidential_info with sed and if the file contains it you can unstage the file. In this way, you won't commit it accidentally.

这篇关于如何始终忽略git上的文件(包含特定行)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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