gpt4 book ai didi

git - 减少 .git 文件夹大小

转载 作者:太空狗 更新时间:2023-10-29 14:41:35 27 4
gpt4 key购买 nike

有这样的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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com