即使您删除了那些“大文件”,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文件并将它复制到你的当前目录。
- 克隆您的 git 存储库(并对其进行备份):
$ git clone --mirror git://example.com/my-large-repo.git
- 运行 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)
....
- 去除不需要的脏数据
$ 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)
...
- 最后推回你的干净回购:
$ git push
来源:here