git,所有分支上的过滤分支
我正在使用以下来源从我的存储库中删除一些大文件和目录:
http://dound.com/2009/04/git-forever-remove-files-or-folders-from-history/
git filter-branch 似乎仅适用于当前分支 - 有没有办法将其立即应用于所有分支?
I'm using the following sources to expunge some large files and directories from my repository:
http://dound.com/2009/04/git-forever-remove-files-or-folders-from-history/
Why is my git repository so big?
git filter-branch
only seems to work on the current branch - is there a way to apply it to all branches at once?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
解决方案很简单:
git filter-branch [options] -- --all
注意
-- - 中的四个破折号(两组双破折号,中间有一个空格) -all
。如果您查看 git-filter-branch 的文档,它会这样说:
继续阅读,文档的开头说:“让您重写 git通过重写中提到的分支来修改历史记录,在每个修订上应用自定义过滤器。”
因此,检查
rev-list
的文档给出:git-rev-list 的文档说:
The solution is simple:
git filter-branch [options] -- --all
Note the four dashes (two sets of double dashes with a space in between) in
-- --all
.If you look at the docs for
git-filter-branch
, it says this:Reading on, the beginning of the docs say: "Lets you rewrite git revision history by rewriting the branches mentioned in the <rev-list options>, applying custom filters on each revision."
So checking the docs for
rev-list
gives:And the docs for
git-rev-list
say:正如 @ben-lee 的回答所解释的,重写所有分支需要
--all
。如果您的存储库中有标签,您将需要清理所有这些以及分支,以便获得减小大小的好处,这将需要额外的--tag-name-filter cat
咒语。尽管问题指定使用 git filter-branch,但提问者想要“从我的存储库中删除一些大文件和目录”,因此值得一提的是,最好的 这样做的工具实际上是 BFG Repo Cleaner,是
git filter-branch
的更简单、更快的替代品。例如:...删除所有大于 10MB 的 blob(不在您的最新提交中),并适用于所有分支和分支。您的存储库中的标签。
全面披露:我是 BFG Repo-Cleaner 的作者。
As @ben-lee's answer explains,
--all
is required for rewriting all branches. If you have tags in your repo, you'll want to clean all those, as well as the branches, in order get the benefits of reduction in size, and that will require an additional--tag-name-filter cat
incantation.Although the question specifies using
git filter-branch
, the questioner wants to 'expunge some large files and directories from my repository', so it's worth mentioning that the best tool for doing that is actually The BFG Repo Cleaner, a simpler, faster alternative togit filter-branch
. For instance:...removes all blobs bigger than 10MB (that aren't in your latest commit), and works on all branches & tags in your repo.
Full disclosure: I'm the author of the BFG Repo-Cleaner.
我按照在 Windows 机器上执行此操作的所有说明进行操作,但一直收到错误,直到我停止使用单引号并改用双引号。
我的动机是我不小心检查了我的
vagrant
环境。以下是从所有分支中删除vagrant
文件夹的命令:只需将
vagrant
替换为您的目录名称,它就会从所有分支中删除该目录。I followed all the instructions for doing this on my Windows box, but I kept getting an error, until I stopped using single quotes and used double quotes instead.
My motivation was that I accidentally checked in my
vagrant
environment. Here's the command to remove thevagrant
folder from all branches:Just replace
vagrant
with your directory name, and it'll remove this directory from all branches.