简体   繁体   English

有没有办法从git存储库中完全删除提交以节省一些空间?

[英]Isn't there any way to completely remove commits from a git repository to save some space?

I want a way to remove (really remove) a commit or a branch from a git repository, for nothing but to save space, i tried to use 'git branch -d branch-name' to remove a branch or 'git reset Head~ --hard' but both just remove or move the branch head, and still the commit exists, and i can reassign a branch head to any commit. 我想要一种方法从git存储库中删除(真正删除)提交或分支,除了节省空间,我试图使用'git branch -d branch-name'删除分支或'git reset Head~ --hard'但是只是删除或移动分支头,仍然存在提交,我可以将分支头重新分配给任何提交。

isn't there a way to do this without removing the entire repository folder and reinitialize? 没有删除整个存储库文件夹并重新初始化,有没有办法做到这一点?

Git builds a nice safety net around your actions, which once in a whille really saves your foot from beeing obliterated. Git围绕你的动作建立了一个很好的安全网,一旦进入一个真正的行动,你的脚就会被淹没。 It is strongly not advised to do what you want to do in a regular daily workflow. 强烈建议不要在日常工作流程中执行您想要执行的操作。

That being said : the commands you are looking for are git gc and git prune . 话虽如此:您正在寻找的命令是git gcgit prune

See for example this SO question : 例如,参见这个SO问题:
git gc --aggressive vs git repack git gc --aggressive vs git repack

You may also need to clear your reflog : 您可能还需要清除您的reflog:
git gc --aggressive --prune=all does not remove big file from repository git gc --aggressive --prune = all不会从存储库中删除大文件

Again : the reflog is like a massive undo stack ; 再说一遍:reflog就像一个巨大的撤销堆栈; if you throw its content away, no more undos. 如果你扔掉它的内容,不再是undos。

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

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