日度归档:2016年5月27日

git: remove big files in historical commits

最近git push一直提示文件太大,无法push,想到应该是自己之前不小心git add *把可执行文件什么的也加入跟踪列表了,于是就想把它们从历史commits中删除,步骤总结如下:

  1. 查看历史提交中有哪些非源代码文件,然后把它们记录下来:
    git log --stat
  2. 删除历史提交中的非源代码文件:
    git filter-branch --tree-filter 'rm -f non_code_files' HEAD
  3. 如果步骤2中漏掉了某些大文件,则可以再执行2中的命令,不过要加一个参数-f:
    git filter-branch -f --tree-filter 'rm -f non_code_files_left' HEAD
  4. 最后把本地提交强制push到远端:
    git push -f
Read the rest