美文网首页
git 如何清理操作日志_git瘦身:清除大文件或敏感文件记录

git 如何清理操作日志_git瘦身:清除大文件或敏感文件记录

作者: kakukeme | 来源:发表于2021-03-10 18:46 被阅读0次

git 如何清理操作日志_git瘦身:清除大文件或敏感文件记录

使用git进行版本管理的项目随着提交代码次数增多,.git目录会逐渐增大。特别是由于没有及时添加进.gitignore的大文件会显著增加.git的大小。另外,由于一时疏忽而上传的敏感文件,即使从工作目录清除还是能在历史记录中查看到。

下面演示的方式就是如何彻底清除git中的大文件或隐私文件。

1、查询git中的大文件记录

git rev-list --objects --all | grep "$(git verify-pack -v .git/objects/pack/*.idx | sort -k 3 -n | tail -5 | awk '{print$1}')"

部分git项目会提示:

Cannot open existing pack file '.git/objects/pack/*.idx'

说明该项目并未触发git的packfile机制,可以忽略。

2、使用BFG Repo-Cleaner

https://rtyley.github.io/bfg-repo-cleaner/
最新版需要确保本地的java为Jdk8+

BFG Repo-Cleaner是一个替代git原生命令git-filter-branch的解决git历史记录问题的方案,BFG Repo-Cleaner的使用更加方便简洁。项目官网:

下载到本地保存为bfg.jar,保证本地的java运行环境可用。

clone项目

git clone --mirror git@github.com:easeapi/test.git

注意:一定要使用--mirror参数。

标记删除文件

java -jar bfg.jar --delete-files (filename) test.git #指定文件删除

java -jar bfg.jar --strip-blobs-bigger-than 100M test.git #条件删除

The BFG will update your commits and all branches and tags so they are clean, but it doesn't physically delete the unwanted stuff. Examine the repo to make sure your history has been updated, and then use the standard git gc command to strip out the unwanted dirty data, which Git will now recognise as surplus to requirements:

删除文件

cd test.git

git reflog expire --expire=now --all && git gc --prune=now --aggressive

推送到远程

git push

参考链接

https://www.jianshu.com/p/60ed9f5e2c05

https://blog.csdn.net/weixin_33179060/article/details/112959190

相关文章

网友评论

      本文标题:git 如何清理操作日志_git瘦身:清除大文件或敏感文件记录

      本文链接:https://www.haomeiwen.com/subject/vatgqltx.html