如何减少Github上的回购规模 [英] How to reduce the size of a repo on Github

查看:144
本文介绍了如何减少Github上的回购规模的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我意外地将一些大的测试wav文件提交到我的存储库中,他们在我的Github帐户上占用了大量空间。如何从历史记录中删除这些文件?

I accidentally committed some large test wav files into my repository and they are using up a lot of space on my Github account. How can I remove these files from the history?

注意:这些文件是前一段时间提交的,不在HEAD提交中。

Note: these files were committed some time ago and are not on the HEAD commit.

推荐答案

如果没有修改历史记录,无法删除它们,因此如果有人拉取更改,则可能需要处理该混乱 - 请参阅从上游恢复 man git-rebase 。这可能会非常糟糕,这取决于您的工作流程 - 无论如何,您可能不得不让每个人都意识到他们需要切换到新主分支,以重新分配正在进行的任何工作。

There's no way to remove them without modifying the history, so if anyone's pulled the changes, you may have to deal with that mess - see recovering from upstream rebase in man git-rebase. This can be pretty bad, depending on your workflow - one way or another you'll probably have to make everyone aware that they need to switch to the "new" master branch, rebasing any work in progress on top of it.

如果提交仍在提示中,您可以重置为之前的提交:

If the commit were still on the tip, you could reset to the commit before it:

git reset --hard HEAD^

或修改它:

git rm test.wav
git commit --amend

但是由于它不再是小费,所以最好的办法可能是用交互式rebase来做:

But since it's no longer at the tip, your best bet is probably to probably do it with an interactive rebase:

git rebase -i <commit-before-mistake>

在您想修复的提交上将pick更改为edit,然后进行编辑! (或者甚至删除整个提交,如果没关系的话)*

Change "pick" to "edit" on the commit you want to fix, then have at it! (or even remove the whole commit if that's okay)*

完成这些选择后,您必须强制推送,因为它不再快进:

After you finish doing whichever of these you pick, you'll have to force the push, since it's no longer a fast-forward:

git push -f origin


*如果您后来对这些文件进行了修改,随着您继续使用这些文件,您将遇到问题。他们应该直截了当地处理,因为你只是想要文件消失。当然,如果自那以后已经有一百次提交都会导致冲突,那么可以看看 git-filter-branch 。来自手册页的相关示例是:

* If you've subsequently committed modifications to these files, you'll get issues as you continue on in the rebase. They should be straightforward to deal with, since you just want the files gone. Of course, if there've been a hundred commits since then that'll all cause conflicts, you could have a look at git-filter-branch. The relevant example from the man page is:

git filter-branch --index-filter ’git rm --cached --ignore-unmatch filename’ HEAD

这篇关于如何减少Github上的回购规模的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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