美文网首页新技能get✔
BFG Repo-Cleaner 的使用

BFG Repo-Cleaner 的使用

作者: AdamSun19 | 来源:发表于2019-08-07 22:24 被阅读0次

官网

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

背景(我为什么要使用这个工具)

最近开发中有一个需求,就是让我从一个仓库clone代码下来,然后提交到另一个仓库,需求确实不算难,理想情况:从一个地址clone下来,然后push到另一个地址,结束。现实:↗↘↗↘↘↗
在往另一个仓库push的时候,发现另一个仓库的服务器不支持这么大的文件(500多M)的库上传。
所以我在询问过负责人之后,告诉我可以把附件删除,只保留代码即可,但是手动删除之后,仓库还是那么大,因为在仓库的历史中还是有这些附件的记录的,所以就需要把这些附件从历史中进行删除。

工具的使用

1、上官网下载BFG Repo-Cleaner的客户端(jar包)

2、使用--mirror克隆一个新的仓库

$ git clone --mirror git://example.com/some-big-repo.git
--mirror 后为仓库地址,可以用https或者ssh

在进行操作之前,最好备份下这个库,操作出了问题用这个备份库即可,不用再重新下载。

下载好的库的格式:


image.png
仓库内的文件格式

ps:在启动客户端时,报错:不是一个有效的库(is not a invalid repository),就按上面的方式重新clone。

3、删除不需要的文件

将下载好的jar放到下载好的git库的同级目录
删除大于100M的文件

$ java -jar bfg.jar --strip-blobs-bigger-than 100M some-big-repo.git
删除大于100M的文件
BFG将更新您的提交以及所有分支和标记,此时还没有物理删除。使用gc去除git认为多余的数据(上面调用命令删除的文件)
$ cd some-big-repo.git
$ git reflog expire --expire=now --all && git gc --prune=now --aggressive

调用上面的命令后,文件将彻底删除(everywhere)。

4、将代码提交到远程仓库

确保文件没有任何问题之后,将代码提交到远程仓库,这将影响远程服务器上所有的refs。

$ git push

如果有必要,让其他人删除原来的仓库,因为原来的仓库中还是有脏数据,有可能会再次提交到远程仓库。

5、其他命令

1.删除所有的名为'id_dsa'或'id_rsa'的文件
$ java -jar bfg.jar --delete-files id_{dsa,rsa}  my-repo.git

2.删除所有大于50M的文件
$ java -jar bfg.jar --strip-blobs-bigger-than 50M  my-repo.git

3.删除文件夹下所有的文件
$ java -jar bfg.jar --delete-folders doc  my-repo.git

6、注意

删除文件后别忘了gc命令,工具不会清除最近一次提交的文件内容,如果需要删除,使用
--no-blob-protection,官方不推荐。在删除前最好确保最新的提交为干净的。

7、详细命令

bfg 1.13.0
Usage: bfg [options] [<repo>]

  -b, --strip-blobs-bigger-than <size>
                           strip blobs bigger than X (eg '128K', '1M', etc)
  -B, --strip-biggest-blobs NUM
                           strip the top NUM biggest blobs
  -bi, --strip-blobs-with-ids <blob-ids-file>
                           strip blobs with the specified Git object ids
  -D, --delete-files <glob>
                           delete files with the specified names (eg '*.class', '*.{txt,log}' - matches on file name, not path within repo)
  --delete-folders <glob>  delete folders with the specified names (eg '.svn', '*-tmp' - matches on folder name, not path within repo)
  --convert-to-git-lfs <value>
                           extract files with the specified names (eg '*.zip' or '*.mp4') into Git LFS
  -rt, --replace-text <expressions-file>
                           filter content of files, replacing matched text. Match expressions should be listed in the file, one expression per line - by default, each expression is treated as a literal, but 'regex:' & 'glob:' prefixes are supported, with '==>' to specify a replacement string other than the default of '***REMOVED***'.
  -fi, --filter-content-including <glob>
                           do file-content filtering on files that match the specified expression (eg '*.{txt,properties}')
  -fe, --filter-content-excluding <glob>
                           don't do file-content filtering on files that match the specified expression (eg '*.{xml,pdf}')
  -fs, --filter-content-size-threshold <size>
                           only do file-content filtering on files smaller than <size> (default is 1048576 bytes)
  -p, --protect-blobs-from <refs>
                           protect blobs that appear in the most recent versions of the specified refs (default is 'HEAD')
  --no-blob-protection     allow the BFG to modify even your *latest* commit. Not recommended: you should have already ensured your latest commit is clean.
  --private                treat this repo-rewrite as removing private data (for example: omit old commit ids from commit messages)
  --massive-non-file-objects-sized-up-to <size>
                           increase memory usage to handle over-size Commits, Tags, and Trees that are up to X in size (eg '10M')
  <repo>                   file path for Git repository to clean

相关文章

  • BFG Repo-Cleaner 的使用

    官网 https://rtyley.github.io/bfg-repo-cleaner/最新版需要确保本地的ja...

  • 使用 BFG Repo-Cleaner 修改 Git 提交历史

    为什么要修改 Git 提交历史 修改 Git 历史,一般有以下两个原因: 删除密码、API Key 等敏感数据,因...

  • BFG Repo-Cleaner - 从 Git 历史中真正删除

    背景 Git 操作时,经常“不小心”上传一些不必要的(大)文件,或者私密数据,等等。 当然可以从本地把这些文件删除...

  • BFG 移除 Git仓库中大文件和隐私文件

    准备条件 [下载 BFG工具] (https://rtyley.github.io/bfg-repo-cleane...

  • BFG

    不知道你有没有看过斯皮尔伯格的《圆梦巨人》,这部电影的口碑与豆瓣评分并不高,可是,在我看来,这并不是一部拍给大人看...

  • THE BFG

    真是一个奇妙的故事,等我看完《圆梦巨人》再抬头看看周围,是一群为考研为梦想奋笔疾书的同学,天黑了,我看着窗户觉得会...

  • The BFG

    《The BFG》 was written by Roald Dahl, I think it's a great...

  • 另一个Git高效清理工具 git-filter-repo

    Introduction BFG功能太简单,杀鸡可以,宰牛差点 BFG的体系结构即使在预期的用例中也存在一些缺点和...

  • The BFG--The big friendly giant

    书名:The BFG 作者:Roald Dahl 出版信息:2010年 页数:272页 阅读日期:201704-4...

  • 学习链接

    1.MyBatis 中的九种设计模式! https://mp.weixin.qq.com/s/d_2Pom9Bfg...

网友评论

    本文标题:BFG Repo-Cleaner 的使用

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