git 如何清理操作日志,清理git历史记录

In one of my projects (checked into a git repository) I have added a huge directory (15000 files, 3GB). When I realized this was wrong, I deleted it, but it seems like it is still in history.

Having it still there makes a project clone a very long task. Once the project is cloned, the .git directory is about 4GB but the real project size is just 15MB.

My question is: how can I tweak the history such as I make sure that 3GB directory is deleted? Or is there another way to decrease the entire project download size and speed up the clone process?

解决方案

So you know which commit introduced the huge directory. Say this was done in revision AAAAAAA.

To get rid of the commit, it is not sufficcient to delete the directory (with commit BBBBBBB) and check in again: the commit AAAAAAA is still there, blowing up your repo size.

To get rid of the commit, we need git rebase. Open your git console and type

git rebase -i AAAAAAA~1

This will bring up an editor where the commit AAAAAAA is in the first line. Remove this line (i.e. when Vim is your editor, hit dd) and the commit where you removed the directory again (BBBBBBB), save the file and quit (:wqa).

After this, rebasing starts and when it has finished, AAAAAAA and BBBBBBB are no longer there. Really.

You could now also trigger some housekeeping with git gc and fetch a cup of coffee while it's running.

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值