git
› Pro Git
› Atlassian Git Tutorial
› Pro Git 简体中文翻译
› GitX
ashfinal
V2EX  ›  git

git 怎么删除之前 commit 的二进制文件?

  •  
  •   ashfinal · Aug 22, 2017 · 4031 views
    This topic created in 3372 days ago, the information mentioned may be changed or developed.

    之前还是太年轻,直接把 readme 的截图放到了 repo 里。结果眼看 repo 越来越大,越来越大……距离提交/修改截图已经过去了好几十个 commit,而核心代码才 200 多 ㎅。怎么才能把二进制文件彻底干掉呢?

    7 replies  •  2017-08-22 21:29:18 +08:00
    zenxds
    zenxds
    Aug 22, 2017
    1
    git rm 不会么
    timothyye
    timothyye
    Aug 22, 2017 via Android
    2
    git rm,再加个 gitignore 屏蔽不需要提交的文件
    kkk330
    kkk330
    Aug 22, 2017
    3
    git rm --cached xxx.jpg
    ashfinal
    ashfinal
    OP
    Aug 22, 2017
    5
    @yangg 操作完看了下还在。
    我用的命令是:
    ``` shell
    git filter-branch --force --index-filter \
    'git rm --cached --ignore-unmatch screenshots/20160328-115751.png' \
    --prune-empty --tag-name-filter cat -- — all
    ```

    我这路径填写的不对?
    oott123
    oott123
    Aug 22, 2017 via Android
    6
    推荐 bfg
    ashfinal
    ashfinal
    OP
    Aug 22, 2017
    7
    搞定了。后面还需要三个命令:
    ``` shell
    $ git reflog expire --expire=now --all
    $ git gc --prune=now
    $ git gc --aggressive --prune=now
    ```
    成功把 repo 从 7 MB 降到了 1 MB。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1031 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 18:13 · PVG 02:13 · LAX 10:13 · JFK 13:13
    ♥ Do have faith in what you're doing.