git - 减少 .git 文件夹大小

标签 git github

有这样的question虽然是旧的,但它似乎没有帮助。 我有 repo .在 repo 协议(protocol)中,我有一个大约 6MB 的 gif 文件。碰巧我推送了这个 GIF 的不同版本,显然它们都存储在 .git 文件夹中,这使得 git 文件夹的大小约为 40MB。

从我尝试按照链接问题中的建议运行的项目文件夹:

   git repack -a -d --depth=250 --window=250

但这并没有影响 .git 文件夹的大小(我是否必须按下才能看到大小减小?)。 我可以做些什么来减少 .git 文件夹的大小吗?

同时尝试 git gc 似乎并没有减少 .git 文件夹的大小。

最佳答案

一个 hacky 解决方案:

git push # ensure that you push all your last commits from all branches, and
         # take care about your stashes as well because we are going to delete
         # everything.
cd ..
rm -rf online-shop
git clone --depth 1 git@github.com:giorgi-m/online-shop.git

这最后一行将克隆只有一个提交历史的存储库。

因此你的 .git文件夹会轻很多。但是,您的计算机上不会有完整的历史记录,这可能不是您要找的。

对于其他想要克隆您的应用程序的用户,您可以在 README 中告诉他们他们可以使用下一个命令来加快下载的文件:

git clone --depth 1 git@github.com:giorgi-m/online-shop.git

另一种解决方案,即rewriting history ,将删除您所有的远程历史记录。您可以在 this answer 中查看更多相关信息:

Deleting the .git folder may cause problems in your git repository. If you want to delete all your commit history but keep the code in its current state, it is very safe to do it as in the following:

Checkout

git checkout --orphan latest_branch

Add all the files

git add -A

Commit the changes

git commit -am "commit message"

Delete the branch

git branch -D master

Rename the current branch to master

git branch -m master

Finally, force update your repository

git push -f origin master

PS: this will not keep your old commit history around

关于git - 减少 .git 文件夹大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53597384/

相关文章:

git - 从 master 分支构建到 gh-pages 分支

git - .git 对象文件夹中缺少哈希

git - git-diff 出现意外结果

windows - 使用网络驱动器作为 git 存储库

用于迁移多个提交的 git rebase?

移动文件的 Git merge

Git 不忽略文件

linux - git clone 无法通过 HTTP 开始中继

git - 你如何从git中的一个且唯一的一个分支中删除文件

由于(假设)未跟踪的文件导致文件覆盖的 Git 警告