本文介绍了用重写的Git回购历史记录更新开发团队,删除大文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个git repo,里面有一些非常大的二进制文件。我不再需要它们,而且我也不在乎能否检出早期提交的文件。所以,为了减少回购大小,我想从历史中删除二进制文件。

I have a git repo with some very large binaries in it. I no longer need them, and I don't care about being able to checkout the files from earlier commits. So, to reduce the repo size, I want to delete the binaries from the history altogether.

在网络搜索之后,我得出结论,我最好的(唯一的)选项是使用 git-filter-branch

After a web search, I concluded that my best (only?) option is to use git-filter-branch:

git filter-branch --index-filter 'git rm --cached --ignore-unmatch big_1.zip big_2.zip etc.zip' HEAD

到目前为止,这看起来是不错的方法吗?

Does this seem like a good approach so far?

假设答案是肯定的,我还有另一个问题需要解决。 :

Assuming the answer is yes, I have another problem to contend with. The git manual has this warning:

我们在我们的服务器上有一个远程回购。每个开发人员推动并从中拉出。基于上面的警告(以及我对 git-filter-branch 的工作原理的理解),我不认为我可以运行 git-filter-branch 在我的本地副本上,然后推送更改。

We have a remote repo on our server. Each developer pushes to and pulls from it. Based on the warning above (and my understanding of how git-filter-branch works), I don't think I'll be able to run git-filter-branch on my local copy and then push the changes.

所以,我暂时计划通过以下步骤:

So, I'm tentatively planning to go through the following steps:


  1. 告诉我的所有开发人员提交,推送并停止工作。

  2. 登录到服务器并在中央仓库上运行筛选器。

  3. 让每个人都删除旧副本,并再次从服务器克隆。

这听起来是对的吗?这是最好的解决方案吗?

Does this sound right? Is this the best solution?

推荐答案

是的,您的解决方案将起作用。您还有另一种选择:不要在中央仓库中执行此操作,请在克隆上运行筛选器,然后使用 git push --force --all 将其推回。这将强制服务器接受存储库中的新分支。这仅替换第2步;其他步骤将是相同的。

Yes, your solution will work. You also have another option: instead of doing this on the central repo, run the filter on your clone and then push it back with git push --force --all. This will force the server to accept the new branches from your repository. This replaces step 2 only; the other steps will be the same.

如果您的开发人员非常熟悉Git,那么他们可能不必删除其旧副本;例如,他们可以获取新的遥控器并根据需要重新标记他们的主题分支。

If your developers are pretty Git-savvy, then they might not have to delete their old copies; for example, they could fetch the new remotes and rebase their topic branches as appropriate.

这篇关于用重写的Git回购历史记录更新开发团队,删除大文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 20:26