在 git commit 之前隐藏文件中的字符串 [英] Hide a string in a file before git commit

查看:17
本文介绍了在 git commit 之前隐藏文件中的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望每次提交更改时隐藏特定文件中的特定字符串.

I would like a specific string in a specific file to be hidden every time I commit changes to that file.

实际上,我在一个不应在远程存储库中公开的文件中有一个 URL.有没有办法使用预提交和提交后挂钩或类似的东西来隐藏它?

Actually, I have a URL in a file that shouldn't be public in a remote repository. Is there anyway to hide it using pre-commit and post-commit hooks or something similar?

目前我正在使用 git 存储库,但很高兴知道如何使用 svn 做到这一点.

Currently I am working with a git repository but it would be nice to know how to do this with svn.

谢谢,思芒

推荐答案

如果您确实必须将该文件置于版本控制之下,请使用 git 属性过滤器驱动程序(另见 GitPro 书籍).

If you really must have that file under version control, use a git attribute filter driver (see also GitPro book).

过滤器驱动程序由一个 clean 命令和一个 smudge 命令组成,其中任何一个都可以不指定.
checkout 时,当指定 smudge 命令时,该命令从其标准输入中获取 blob 对象,其标准输出用于更新工作树文件.
类似地,clean 命令用于在签入时转换工作树文件的内容.

A filter driver consists of a clean command and a smudge command, either of which can be left unspecified.
Upon checkout, when the smudge command is specified, the command is fed the blob object from its standard input, and its standard output is used to update the worktree file.
Similarly, the clean command is used to convert the contents of worktree file upon check-in.

这样,smudge 引用的脚本(私有版本,只在你的 repo 中,不由 Git 管理)可以替换编码后的 URL,而 clean 脚本会将其内容恢复为编码网址.
由 git 管理并随处推送的相同脚本的公共版本将不会做任何事情......并且保持 URL 混淆.

That way, the script (a private version, only in your repo, not managed by Git) referenced by the smudge can replace the coded URL, while the clean script will restore its content to a coded URL.
A public version of the same script, managed by git and pushed everywhere would do... nothing and keep the URL obfuscated.

这篇关于在 git commit 之前隐藏文件中的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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