在 git commit 之前隐藏文件中的字符串
我希望每次提交对该文件的更改时隐藏特定文件中的特定字符串。
实际上,我的文件中有一个 URL,该 URL 不应该在远程存储库中公开。无论如何,是否可以使用提交前和提交后挂钩或类似的东西来隐藏它?
目前我正在使用 git 存储库,但很高兴知道如何使用 svn 来做到这一点。
谢谢, 西芒
I would like a specific string in a specific file to be hidden every time I commit changes to that file.
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?
Currently I am working with a git repository but it would be nice to know how to do this with svn.
Thanks,
Simão
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将该字符串保存在单独的文件中(例如资源文件,如果您的环境支持的话),而不将该文件置于版本控制之下。
You could keep that string in a separate file (such as a resource file, if your environment supports that), and not put that file under version control.
如果您确实必须将该文件置于版本控制之下,请使用 git 属性过滤器驱动程序(另请参阅GitPro 书籍)。
这样,污点引用的脚本(私有版本,仅在您的存储库中,不受 Git 管理)可以替换编码的 URL,而干净的脚本会将其内容恢复为编码的 URL。
同一脚本的公共版本,由 git 管理并推送到任何地方,不会执行任何操作,并且会使 URL 变得模糊。
If you really must have that file under version control, use a git attribute filter driver (see also GitPro book).
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.