zoukankan      html  css  js  c++  java
  • git 仓库中删除历史大文件

    git 仓库中删除历史大文件


    在git中增加了一个很大的文件,而且被保存在历史提交记录中,每次拉取代码都很大,速度很慢。而且用删除
    提交历史记录的方式不是很实际。
    以下分几个步骤介绍如何减小.git文件夹

    1.显示10个最大的文件id列表

    git verify-pack -v .git/objects/pack/pack-*.idx | sort -k 3 -g | tail -10

    $ git verify-pack -v .git/objects/pack/pack-*.idx | sort -k 3 -g | tail -10
    f830d5449f307e45915c2544dfef902cfbfab5d9 blob   3714990 2811488 60010494
    986d0c3904de8a3b08c17b5feb9f29da442ebfd4 blob   5912773 5542283 31754
    c1fd4cf06c9836d1bbd0344729af99a9e5e5f32c blob   7959920 7872976 234245152
    90d45f4b62ce20fb4ff733e83267152951edad97 blob   28553670 28557775 205684107
    a2f423946a59e4a2c83955f4af4d19dc1f048e5f blob   45041599 43163608 74595714
    4949ea380952b32c412943ed77fb36fd5be35e84 blob   45337600 7431701 62822673
    4564140f9e8ee9fefb65db2ae33a8b8a90dc29d3 blob   54272873 54107977 242200239
    09401d185a5cdafadc33105b1d62b868328c0dba blob   54639114 54423305 5574037
    6562f64e52e205bce49f9611e04e82a0e0f956db blob   129540654 82626130 122357710
    3b08a747589895bdc995cd18ae1fe9e70abcd417 blob   697131332 691555610 296308295
    

    2. 根据文件id查询文件路径

    git rev-list --objects --all | grep 3b08a747589895bdc995cd18ae1fe9e70abcd417

    $ git rev-list --objects --all | grep 3b08a747589895bdc995cd18ae1fe9e70abcd4173b08a747589895bdc995cd18ae1fe9e70abcd417 yunos_compile/aarch64-linux-gnueabi-4.9-glibc-2.20.tgz
    

    3. 移除文件

    git log --pretty=oneline --branches -- your_file

    $ git log --pretty=oneline --branches -- yunos_compile/aarch64-linux-gnueabi-4.9-glibc-2.20.tgz8cc32c6b75122f204f4d3efdba30130759076731 add Sparrow monkey test user a32477a611de0e8c60f6e58f7690a759b6577bd4 add yunos_compile
    

    4. 删除文件的历史记录

    git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch --ignore-unmatch your_file' --prune-empty --tag-name-filter cat -- --all

    5. 提交

    git push --force --all
    如果出现提示remote: GitLab: You are not allowed to force push code to a protected branch on this project.
    需要在gitlab里面取消分支protected

    6. 清除本地缓存

    rm -Rf .git/refs/original
    rm -Rf .git/logs/
    git gc
    git prune

  • 相关阅读:
    Python 数字数据类型
    Python 标准数据类型
    Python 变量类型及变量赋值
    Python 基础语法
    ElasticStack系列之五 & 当前的缺陷与不足
    ElasticStack系列之四 & 索引后半段过程
    ElasticStack系列之三 & 索引前半段过程
    ElasticStack系列之二 & ElasticStack整体架构
    ElasticStack系列之一 & ElasticStack基础概念
    c# 获取本机IP
  • 原文地址:https://www.cnblogs.com/langzou/p/9877165.html
Copyright © 2011-2022 走看看