V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
git
Pro Git
Atlassian Git Tutorial
Pro Git 简体中文翻译
GitX
ashfinal
V2EX  ›  git

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

  •  
  •   ashfinal · 2017-08-22 19:32:17 +08:00 · 3239 次点击
    这是一个创建于 2431 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

    7 条回复    2017-08-22 21:29:18 +08:00
    zenxds
        1
    zenxds  
       2017-08-22 19:34:36 +08:00
    git rm 不会么
    timothyye
        2
    timothyye  
       2017-08-22 19:35:32 +08:00 via Android
    git rm,再加个 gitignore 屏蔽不需要提交的文件
    kkk330
        3
    kkk330  
       2017-08-22 19:40:07 +08:00
    git rm --cached xxx.jpg
    yangg
        4
    yangg  
       2017-08-22 19:41:05 +08:00   ❤️ 2
    ashfinal
        5
    ashfinal  
    OP
       2017-08-22 20:21:27 +08:00
    @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  
       2017-08-22 21:14:08 +08:00 via Android
    推荐 bfg
    ashfinal
        7
    ashfinal  
    OP
       2017-08-22 21:29:18 +08:00
    搞定了。后面还需要三个命令:
    ``` shell
    $ git reflog expire --expire=now --all
    $ git gc --prune=now
    $ git gc --aggressive --prune=now
    ```
    成功把 repo 从 7 MB 降到了 1 MB。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3173 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 00:34 · PVG 08:34 · LAX 17:34 · JFK 20:34
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.