简体   繁体   English

删除不需要的文件以减小git存储库的大小

[英]Removing unwanted files to reduce git repository size

As the result of a comedy of errors, a few directories of images totaling about 500MB was added to our git repository a while ago. 由于出现了一系列的错误消息,不久前,一些图像目录(总共约500MB)已添加到我们的git存储库中。 While the files were removed, the history obviously still contains the repository size is much larger than it should be. 删除文件后,历史记录显然仍包含存储库大小,其大小比应有的要大得多。

This occurred a while ago, and there have been thousands of commits since. 这发生在前一段时间,此后已有成千上万次提交。 I've done some research and it looks like the best course of action would be to use a git filter-branch to re-write the history to remove these unwanted (but not sensitive) directories. 我已经做过一些研究,看来最好的做法是使用git filter-branch重新编写历史记录以删除这些不需要的(但不敏感)目录。

Is that correct? 那是对的吗? If so, what is the best course of action for the (small) team of developers and multiple staging/production sites to avoid the pitfalls of history rewrites? 如果是这样,那么对于(小型)开发人员团队和多个暂存/生产站点而言,最佳的做法是什么,以避免历史重写的陷阱?

An alternative to git filter-branch is BFG Repo Cleaner which can do simple tasks like this in a fraction of the time, and takes makes it simpler to make sure that all your tags are copied correctly. git filter-branch的替代方法是BFG Repo Cleaner ,它可以在很短的时间内完成类似的简单任务,并且可以更轻松地确保正确复制所有标签。 It also automatically translates hashes that are included in commit messages correctly. 它还可以自动正确转换提交消息中包含的哈希。

As always when rewriting history, there can be issues. 与往常一样,在重写历史记录时,可能会出现问题。 You will have to force fetch all locations that normally use the default fetch. 您将必须强制获取通常使用默认获取的所有位置。

Any developers that have outstanding branches that have not been pushed to the main repository should be able to rebase onto the new history as follows: 具有未推送到主存储库的未完成分支的任何开发人员都应能够根据以下内容重新建立新的历史记录:

git rebase --onto <new-branch-base> <old-branch-base> <branch-name>

<new-branch-base> is the hash of the commit that you want to the branch to diverge from. <new-branch-base>是您要分支出的提交的哈希值。 <old-branch-base> is the hash of the commit that is a copy of the <new-branch-base> <old-branch-base>是提交的哈希,它是<new-branch-base>的副本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM