清理git历史记录 [英] Cleaning up git history

查看:496
本文介绍了清理git历史记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的一个项目中(签入git仓库),我添加了一个巨大的目录(15000个文件,3GB)。当我意识到这是错误的,我删除了它,但它似乎仍然在历史中。



如果它仍然存在,就会使项目克隆一项非常长的任务。克隆项目后,.git目录约为4GB,但实际项目大小仅为15MB。



我的问题是:如何调整历史记录,例如I确保3GB目录被删除?或者是否有另一种方法来减少整个项目的下载大小并加快克隆过程? 所以你知道哪个提交被引入巨大的目录。假设这是在修订 AAAAAAA 中完成的。



为了摆脱提交,不足以删除目录(提交 BBBBBBB )并再次检入:提交 AAAAAAA 仍然存在,炸毁了您的回购大小。



为了摆脱提交,我们需要 git rebase 。打开你的git控制台并输入

  git rebase -i AAAAAAA〜1 

这将引发一个编辑器,其中提交 AAAAAAA 位于第一行。删除此行(即当Vim是您的编辑器时,点击 d d )以及再次删除目录的提交( BBBBBBB ),保存文件并退出(:wqa )。 在此之后,重新启动开始并结束时, AAAAAAA BBBBBBB 不再存在。真的。

你现在可以用 git gc 并在运行时取一杯咖啡。




另请参阅此答案: git push heroku - 停止heroku推/上传大量文件


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.


See also this answer: git push heroku - stop heroku pushing/uploading massive file

这篇关于清理git历史记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆