git 在推/pull 时加密/解密远程存储库文件

标签 git encryption

是否可以在传输到远程存储库之前通过“git push”自动加密文件?并在“git pull”时自动解码它们。

即,如果我有一些远程服务器与那里的 git 存储库共享访问权限,并且我不希望我们的项目在未经许可的情况下被盗... 也许在推送之前和 pull 之后有一些特殊的 git-hooks?

最佳答案

是也不是。

您可以尝试依赖 hook,但假设它们安装在远程位置,这并不总是可靠的。

另一种实现几乎相同效果的方法是使用 smudge/clean attribute filter driver但不是完整的 repo

smudge/clean

(来源:Pro Git book : Customizing Git - Git Attributes)

这样 smudge 脚本就可以解码文件,而 clean 脚本可以对文件进行编码。
同样,这可能适用于一些敏感文件,不适用于完整的存储库

当然,这些脚本不会在存储库本身中,而是通过另一种方式进行管理/通信。

正如 Alkaline 指出 in the comments 的那样,作为主要的 git 维护者 Junio C. Hamano comments back in 2009,这个想法不能扩展到 repo:

As the sole raison d'etre of diff.textconv is to allow potentially lossy conversion (e.g. msword-to-text) applied to the preimage and postimage pair of contents (that are supposed to be "clean") before giving a textual diff to human consumption.

The above config may appear to work, but if you really want an encrypted repository, you should be using an encrypting filesystem.
That would give an added benefit that the work tree associated with your repository would also be encrypted
.


尽管它没有扩展到完整的代码库,但这个想法是通过 git-crypt 实现的(3 年后的 2013 年),详见 Dominic Cerisanoanswer
git-crypt 使用内容过滤驱动(在 cpp 中实现,commands.cpp 使用相关的 smudge 设置你的 .gitattributes code> 和 clean 过滤器命令)。
作为任何内容过滤器驱动程序,您可以将 git-crypt 的应用程序限制为您想要的文件集,在同一个 .gitattributes 文件中:

secretfile filter=git-crypt diff=git-crypt
*.key filter=git-crypt diff=git-crypt

作为 mentioned in the README:

git-crypt relies on git filters, which were not designed with encryption in mind.

As such, git-crypt is not the best tool for encrypting most or all of the files in a repository.
Where git-crypt really shines is where most of your repository is public, but you have a few files (perhaps private keys named *.key, or a file with API credentials) which you need to encrypt.

For encrypting an entire repository, consider using a system like git-remote-gcrypt instead.

(在 spwhitton/ tech/ code/ git-remote-gcrypt 上查看更多信息,来自 Sean Whitton )

关于git 在推/pull 时加密/解密远程存储库文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2456954/

相关文章:

git - 错误 : cannot lock ref.。 'refs/tags' 存在;无法创建“引用/标签/

git - 如何在 Git 中比较本地主机和远程主机?

php - 在 javascript 中快速 URL 加密,在 php 中解密

android - Android 应用程序中的静态信息在哪里安全保存?

c# - 如何用私钥加密字符串并用公钥解密?

ios - 在 iOS 上通过蓝牙进行类似 TLS 的加密?

Git 期望数字超时?

GitCloneTask 不克隆存储库 ("The remote end hung up unexpectedly")

git - 如何获取 'git clone --recursive' 以在本地克隆子模块?

C# 加密生成 key