从git中 从所有提交记录中删除文件

git filter-branch

将之前提交过的文件从版本中删除

git filter-branch --help

解释
git-filter-branch - Rewrite branches
语法

git filter-branch 
[--env-filter <command>]
[--tree-filter <command>]
[--index-filter <command>]
[--parent-filter <command>]
[--msg-filter <command>] 
[--commit-filter <command>]
[--subdirectory-filter <directory>]
[--prune-empty]
[--original <namespace>] 
[-f | --force]
[--] [<rev-list options>…]

示例

git filter-branch --index-filter 'git rm --cached --ignore-unmatch b.c' -f

–tree-filter表示历史提交。
–index-filter
–msg-filter表示修改提交信息,原提交信息从标准输入读入,新提交信息输出到标准输出。
-f是忽略备份。不加这个选项第二次运行这个命令时会出错,意思是 git 上次做了备份,现在再要运行的话得处理掉上次的备份。

问题

$ du -hs
虽然原文件已经删除了,但查看文件大小还是包括删除的文件,

执行以下git语句则节省大小

git ls-remote . 
rm -rf .git/logs  
git reflog --all  
git prune  
git gc  
du -hs  

在window 命令行行执行有问题,建议在bash.exe中执行,
不要打开多个bash,会出现没权限的问题

可以用一段脚本执行,保存成.bat格式的任意文件名
放在与git项目同级的目录下,demo换成git项目的目录,
因为命令行下运行filter-branch有问题,两句还不能直接加上,高手,知道的可以评论

cd demo 
#bash.exe
#git filter-branch --index-filter 'git rm --cached --ignore-unmatch demo2.txt' -f
#git filter-branch --tree-filter 'git rm --cached --ignore-unmatch demo2.txt' -f
git ls-remote . 
rm -rf .git/logs  
git reflog --all  
git prune  
git gc  
du -hs 

参考
http://weimenlove.blog.163.com/blog/static/17775473201322395251716/

http://blog.csdn.net/king_sundi/article/details/7751906

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值