• 安装git-crypt
brew install git-crypt

上传 push

  • 首先在root仓库目录下完成git-crypt的初始化,其会默认:
    • 生成一个默认的加密 key 文件:.git/git-crypt/keys/default
    • 修改 .git/config,在其中加上 filter 和 diff 相关的配置
git crypt init

image.png

  • 在root仓库目录下添加.gitattributes文件,作用于gitignore类似:
# 加密 encrypted
link/.gauth filter=git-crypt diff=git-crypt
link/.ssh/** filter=git-crypt diff=git-crypt

# 避免加密 not encrypted
.gitignore !filter !diff
.gitattributes !filter !diff
  • 后面查看对哪些文件生效
git-crypt status

image.png

  • 在root仓库目录下生成密钥!
git-crypt export-key git-crypt.key

image.png

  • 在gitignore文件中将其忽略上传!
# ignore
# .gitattributes
git-crypt.key
  • 最后push到远程仓库即可

下载 pull

  • 其他用户将该文件clone下来后先在root仓库下载git-crypt
brew install git-crypt
  • 找原先管理员获取git-crypt.key文件!!

image.png

  • 进行解密操作!
git-crypt unlock git-crypt.key

【拓展】去除加密的文件

当不小心把某个文件设成了加密,或者觉得某个文件没必要再进行加密时,我们可以通过如下的步骤去除对它的加密配置:

  • 在 .gitattributes 中去除这个文件对应的加密配置,提交并 push
  • 在另外的地方 clone 仓库,复制明文的文件替换当前的密文版本,确认无误后,提交并 push
  • 在原来的仓库执行 git pull 操作即可把文件从加密变成非加密版本
Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐