如何减小 Git 仓库大小

huangapple go评论71阅读模式
英文:

How to reduce git repository size

问题

之前我将一些大文件推送到了Git分支,导致存储库大小增加。后来我使用以下方法从该分支中删除了这些冗余文件:

git rm big_file
git commit -m 'rm bg file'
git push origin branch-name

但是Git存储库的文件大小仍然没有改变。

然后我尝试使用这个方法来清除提交历史记录,但它没有起作用,存储库大小仍然保持不变。

英文:

Earlier I pushed some big files to git branch which increased the repository size. Later I removed those redundant files from that branch using,

git rm big_file
git commit -m 'rm bg file'
git push origin branch-name

But the file size of git repository remained unchanged.

Then I tried using this method to clear commit history but it didn't worked, the repo size is still the same.

答案1

得分: 4

你已经从最后一次提交中删除了大文件,你需要从之前的提交中也删除它,否则你的存储库大小不会减小。

你应该使用这个工具来清理你的存储库历史记录:

https://rtyley.github.io/bfg-repo-cleaner/

它是这种任务的完美工具。

BFG Repo-Cleaner

一个替代 git-filter-branch 的工具。

BFG 是一个简单、快速的替代品,用于从 Git 存储库历史记录中清除不良数据:

  • 删除超大文件
  • 删除密码、凭据和其他私人数据

示例(来自官方网站)
在所有这些示例中,bfg 是 java -jar bfg.jar 的别名。

删除所有名为 'id_rsa' 或 'id_dsa' 的文件:

bfg --delete-files id_{dsa,rsa} my-repo.git

如何减小 Git 仓库大小

英文:

You have deleted the big file only from the last commit, you will need to delete it from earlier commits as well, otherwise, your repository size will not be reduced.

You should use this tool to clean your repository history:

https://rtyley.github.io/bfg-repo-cleaner/

It the prefect tool for this kind of task.

> ### BFG Repo-Cleaner
>
> an alternative to git-filter-branch.
>
> The BFG is a simpler, faster alternative to git-filter-branch for cleansing bad data out of your Git repository history:
>
> * Removing Crazy Big Files
> * Removing Passwords, Credentials & other Private data

Examples (from the official site)

> In all these examples bfg is an alias for java -jar bfg.jar.

# Delete all files named 'id_rsa' or 'id_dsa' :
bfg --delete-files id_{dsa,rsa}  my-repo.git

如何减小 Git 仓库大小

答案2

得分: 1

这个Atlassian文档在所有Git产品中大致相同:https://confluence.atlassian.com/bitbucket/maintaining-a-git-repository-321848291.html
它包括BFG和git filter branch方法。
我之前使用过BFG和filter branch方法。BFG效果很好。
这份文档还有助于避免这种类型的提交:https://confluence.atlassian.com/bitbucket/reduce-repository-size-321848262.html

英文:

This Atlassian Document works more or less the same with all git products: https://confluence.atlassian.com/bitbucket/maintaining-a-git-repository-321848291.html
It includes BFG and git filter branch methods together.
I've previously used both BFG and filter branch methods . BFG works fine.
This documentation also helps to avoid such type of commits https://confluence.atlassian.com/bitbucket/reduce-repository-size-321848262.html

huangapple
  • 本文由 发表于 2020年1月6日 17:34:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/59609655.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定