删除由git创建的大型.pack文件 [英] Remove large .pack file created by git
问题描述
我检查了一个文件负载到一个分支并合并,然后不得不删除它们,现在我剩下一个大的.pack文件,我不知道如何摆脱。
我使用 git rm -rf xxxxxx
删除了所有文件,并且还运行了 --cached
选项。
有人可以告诉我如何删除当前位于以下目录中的大型.pack文件:
.git / objects / pack / pack-xxxxxxxxxxxxxxxxx.pack
我是否需要删除我仍然拥有但不再使用的分支?或者还有其他需要运行的东西?
我不确定它有多大的差异,但是它显示了一个针对该文件的挂锁。
谢谢
编辑
<这里是我的bash_history的一些摘录,应该给出我如何设法进入这种状态的一个想法(假设在这一点上我正在研究一个名为'my-branch'的git分支,并且我有一个包含更多文件夹/文件):
git add。
git commit -m将我的分支更改添加到master
git checkout master
git合并my-branch
git rm -rf unwanted_folder /
rm -rf unwanted_folder /(不知道为什么我这样做,但我做到了)
我以为我也跑了下面但它并没有出现在bash_history中:
git rm -rf --cached unwanted_folder /
我也想过我运行了一些git命令(比如 git gc
)试图整理包文件,但它们也不会出现在.bash_history文件中。
问题是即使你删除了这些文件,它们仍然存在于以前的版本中。这就是git的重点,即使你删除了一些东西,你仍然可以通过访问历史来获取它。
你要做的就是改写历史,它涉及 git filter-branch
命令。
GitHub对它们的问题有很好的解释现场。 https://help.github.com/articles/remove-sensitive-data
为了更直接地回答你的问题,你基本上需要运行的是这样的:
git filter-branch --index-filter'git rm -r --cached --ignore-unmatch unwanted_folder'--prune-empty
这将删除所有对repo历史文件的引用。
接下来,您需要运行它 git gc --aggressive --prune
I checked a load of files in to a branch and merged and then had to remove them and now I'm left with a large .pack file that I don't know how to get rid of.
I deleted all the files using git rm -rf xxxxxx
and I also ran the --cached
option as well.
Can someone tell me how I can remove a large .pack file that is currently in the following directory:
.git/objects/pack/pack-xxxxxxxxxxxxxxxxx.pack
Do I just need to remove the branch that I still have but am no longer using? Or is there something else I need to run?
I'm not sure how much difference it makes but it shows a padlock against the file.
Thanks
EDIT
Here are some excerpts from my bash_history that should give an idea how I managed to get into this state (assume at this point I'm working on a git branch called 'my-branch' and I've got a folder containing more folders/files):
git add .
git commit -m "Adding my branch changes to master"
git checkout master
git merge my-branch
git rm -rf unwanted_folder/
rm -rf unwanted_folder/ (not sure why I ran this as well but I did)
I thought I also ran the following but it doesn't appear in the bash_history with the others :
git rm -rf --cached unwanted_folder/
I also thought I ran some git commands (like git gc
) to try to tidy up the pack file but they don't appear in the .bash_history file either.
The issue is that, even though you removed the files, they are still present in previous revisions. That's the whole point of git, is that even if you delete something, you can still get it back by accessing the history.
What you are looking to do is called rewriting history, and it involved the git filter-branch
command.
GitHub has a good explanation of the issue on their site. https://help.github.com/articles/remove-sensitive-data
To answer your question more directly, what you basically need to run is this:
git filter-branch --index-filter 'git rm -r --cached --ignore-unmatch unwanted_folder' --prune-empty
This will remove all references to the files from the history of the repo.
Next, you'll want to run this, to actually remove the files from the packfile.
git gc --aggressive --prune
这篇关于删除由git创建的大型.pack文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!