【问题标题】:Clear 'hiiden' large files in gitlab repo清除 gitlab 存储库中的“隐藏”大文件
【发布时间】:2022-01-01 00:26:25
【问题描述】:

我知道我备份到gitlab 的文件是python 脚本文件和jupyter 笔记本。但是,我的 gitlab 存储库说我目前使用的是 9.8GB(令人震惊!)。

我真的不打算将大文件提交到repo(例如数据文件)。目视检查没有显示那些大文件,所以我可以删除它们。我看到的只是 python 脚本文件。

如何清除我的repo 中的那些大文件?

【问题讨论】:

标签: git gitlab storage


【解决方案1】:

即使您删除了那些“大文件”,gitlab 仍然可以使用大文件提交历史。您可以使用来自this 答案的以下脚本查看这些文件列表。

git rev-list --objects --all |
  git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' |
  sed -n 's/^blob //p' |
  sort --numeric-sort --key=2 |
  cut -c 1-12,41- |
  $(command -v gnumfmt || echo numfmt) --field=2 --to=iec-i --suffix=B --padding=7 --round=nearest

首先创建一个脚本文件并赋予可执行文件权限为:

vim history.sh   # and paste the above script into the file
chmod +x history.ch # give file exe permission

./history.sh  # to run file

这将报告所有提交历史记录和文件大小,如下所示:

....
192e100aaf93  2.8MiB SMF/Checking/models/Model_0.h5
1b808a1a25ba  2.8MiB SMF/Checking/models/Model_2.h5
80168dc7ffb54 1.3GiB SMF/data/segments_instances_final.csv
775b60418498  1.5GiB Revised_KerasData_NoSmoothing.pickle
2341792d8c9b  4.2GiB geolife.sql
......

删除大文件

使用BFG-repo-cleaner 清理这些文件:

注意:假设你已经安装了java,下载上面repo的bfg.jar文件并将它复制到你的当前目录。

  1. 克隆您的 git 存储库(并对其进行备份):
$ git clone --mirror git://example.com/my-large-repo.git 
  1. 运行 BFG 以清理您的存储库(例如清理大于 50MB 的文件):
$ java -jar bfg.jar --strip-blobs-bigger-than 100M my-large-repo.git

....
                            Before     After   
    -------------------------------------------
    First modified commit | fc7cf2f9 | a772ae4a
    Last dirty commit     | d4a1a3d4 | 9b345832

Deleted files
-------------

    Filename                                                    Git id                                                       
    -------------------------------------------------------------------------------------------------------------------------
    3Class_Instances.pkl                                      | ceebb395 (558.1 MB)                                          
    Beijing_KerasData.pkl                                     | 8681a270 (133.4 MB)                                          
    Filtered_Trajectory.pkl                                   | bfe06d09 (137.8 MB)    
      ....
  1. 去除不需要的脏数据
$ cd my-large-repo.git
$ git reflog expire --expire=now --all && git gc --prune=now --aggressive

Enumerating objects: 1306, done.
Counting objects: 100% (1306/1306), done.
Delta compression using up to 8 threads
Compressing objects:  78% (973/1238)238)
...
  1. 最后推回你的干净回购:
$ git push

来源:here

【讨论】:

  • 非常感谢您的详细回答。我很感激。
猜你喜欢
  • 2018-03-18
  • 2019-05-15
  • 1970-01-01
  • 2022-08-18
  • 2017-05-24
  • 2021-03-13
  • 1970-01-01
  • 2016-02-09
  • 2021-09-17
相关资源
最近更新 更多