Completely delete large files in git (including historical records submitted)

Disclaimer: This article is a blogger original article, follow the  CC 4.0 by-sa  copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/HappyRocking/article/details/89313501

Scenes

Applies to the larger volume of resources to completely remove from a git project from the git, the author includes historical record.

If only delete a file in the directory is not enough, as long as the file submitted to the record, then  .git the file will have this information.

Use  filter-branch can be forced to modify the information submitted, the history of a file submitted to erase the traces of like this has never been the same file.

practice

0 ensure that local warehouse is the latest version.

1, run in the project root directory

git rev-list --all | xargs -rL1 git ls-tree -r --long | sort -uk3 | sort -rnk4 | head -10

List all repository objects (including SHA value, size, path, etc.), and by size in descending order, are listed TOP 10.

$ git rev-list --all | xargs -rL1 git ls-tree -r --long | sort -uk3 | sort -rnk4 | head -10 100644 blob 71ac1de8ee83566cca68f69d54acd82b9abf607d 7701044 "attr_matching/\346\240\207\346\263\250\346\226\207\344\273\266Win\346\216\222\345\272\2171-54000.xlsx" 100644 blob d610f01bc315becaaa1c6d04772689d80ad4d010 7532106 "attr_matching/\346\240\207\346\263\250\346\226\207\344\273\266Win\346\216\222\345\272\2171-58000.xlsx" 100644 blob 72b8fd2eeb1c951a7f680e6f4031fa57d643ebe1 5717635 personal_label_project/personal_label_ocr/result/matrix.csv 100644 blob 89363c480afb229b5df4e2f6a6a951fdebca5ce2 5501428 cloth_attribute_classification/nohup_1103.out 100644 blob 7cdba6a4e584a49dcab693111a90f2bdb0030a3c 5392316 sheos_category_classification/nohup_gpu_category_33_0.out 100644 blob 84149a46904f87495df4896698ca5dd6fb53bdf3 5226094 cloth_attribute_classification/nohup_1105.out 100644 blob c77db27ae9fbb5450586daa3c9622766d7a4a9bc 5151535 attr_matching/OCR_result_correct.txt 100644 blob 58e4647427c443a44fbc66d584f6bda21b7c9036 2785190 image_check/out_tmp/nohup_5w_test_sheos.out 100644 blob 58e4647427c443a44fbc66d584f6bda21b7c9036 2785190 image_check/out_tmp/nohup_50000_sheos.out 100644 blob 58e4647427c443a44fbc66d584f6bda21b7c9036 2785190 image_check/nohup_5w.out 

2. The maximum file path  {filepath}, modify the commit history of this file:

git filter-branch --tree-filter "rm -f {filepath}" -- --all

3, forced to submit to a remote branch:

git push -f --all

4, complete. You can re-download items, lists all the objects in the warehouse to see if there are file you just deleted.

Guess you like

Origin www.cnblogs.com/dousnl/p/11428285.html