可以使用 git hook 在暂存、添加或推送之前替换密码吗?

发布于 2024-11-04 02:38:40 字数 196 浏览 0 评论 0原文

可以使用 git hook 在暂存、添加或推送之前替换密码吗?

我希望在提交或推送之前将密码替换为模板。

例如,假设我在纯文本密码中添加了“PWDEXLUDE_password”前缀,并且钩子将其替换为 <>,因此在部署阶段,脚本可以查找模板,在数据库中查找密码,并将该模板替换为生产密码。

git 有类似的东西吗?

Can a git hook be used to replace passwords before staging, adding, or pushing?

I want passwords to be replaced by templates before committing or pushing.

for instance, say I prefix plain texts password with 'PWDEXLUDE_password' and the hook replaces it with <>, so during the deployment phase a script can look for the template, lookup in a database for the password, and substitute that template with production password.

Is something like that available or possible with git?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

鸠魁 2024-11-11 02:38:40

我会采取不同的方法,即将密码保存在不受版本控制的配置文件中,并让应用程序在运行时从该文件加载它们。你的部署脚本只需要确保这样的文件存在,并且每个开发人员都可以有自己的密码进行开发和测试。

如果您真的想做您所要求的事情,我认为您可以在预提交中完成钩子,提取包含密码的文件的暂存版本,重写它们,然后暂存重写的版本,确保不会影响工作副本。然而,出于多种原因,这对我来说似乎是一个坏主意。

I would take a different approach, which would be to keep passwords in a configuration file that's not under version control and have your application load them from that file when it runs. Your deploy script just needs to ensure that such a file exists, and each developer can have their own passwords for development and testing.

If you really want to do what you ask, I think you could do it in a pre-commit hook that extracts the staged versions of the files with passwords in them, rewrites them, and stages the rewritten version, making sure not to affect the working copy. However, this seems like a bad idea to me for any number of reasons.

深爱不及久伴 2024-11-11 02:38:40

我认为这里正确的事情(如果你不想要一个被忽略的文件,我也更喜欢)是一对涂抹/清洁过滤器。请参阅 gitattributes 中的过滤部分

I think the right thing here (if you don't want an ignored file, which I would prefer, too) would be a pair of smudge/clean filters. See the filter section in gitattributes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文