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

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

  •  
  •   ashfinal · Aug 22, 2017 · 3798 views
    This topic created in 3215 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
        1
    zenxds  
       Aug 22, 2017
    git rm 不会么
    timothyye
        2
    timothyye  
       Aug 22, 2017 via Android
    git rm,再加个 gitignore 屏蔽不需要提交的文件
    kkk330
        3
    kkk330  
       Aug 22, 2017
    git rm --cached xxx.jpg
    ashfinal
        5
    ashfinal  
    OP
       Aug 22, 2017
    @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
        6
    oott123  
       Aug 22, 2017 via Android
    推荐 bfg
    ashfinal
        7
    ashfinal  
    OP
       Aug 22, 2017
    搞定了。后面还需要三个命令:
    ``` 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   ·   Solana   ·   3646 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 50ms · UTC 04:35 · PVG 12:35 · LAX 21:35 · JFK 00:35
    ♥ Do have faith in what you're doing.