在所有分支上分支

我正在使用以下源来从我的存储库中删除一些大文件和目录:

http://dound.com/2009/04/git-forever-remove-files-or-folders-from-history/

为什么我的git存储库如此之大?

git filter-branch似乎只适用于当前分支 - 有没有办法一次将它应用到所有分支?


解决方案很简单:

git filter-branch [options] -- --all

注意四条破折号(两组双破折号之间的空格)in -- --all

如果你看看git-filter-branch的文档,它会这样说:

git filter-branch [--env-filter <command>] [--tree-filter <command>]
    [--index-filter <command>] [--parent-filter <command>]
    [--msg-filter <command>] [--commit-filter <command>]
    [--tag-name-filter <command>] [--subdirectory-filter <directory>]
    [--prune-empty]
    [--original <namespace>] [-d <directory>] [-f | --force]
    [--] [<rev-list options>…]

阅读文档的开头部分说:“让您通过重写<rev-list选项>中提到的分支来重写git修订历史记录,并在每个修订版上应用自定义过滤器。”

因此,检查rev-list的文档给出:

<rev-list options> ... git rev-list的参数。 这些选项包含的所有正面参考都被重写。 你也可以指定诸如--all这样的选项,但你必须使用 - 将它们与git filter-branch选项分开。

git-rev-list的文档说:

--all
Pretend as if all the refs in refs/ are listed on the command line as <commit>.

作为@奔-李的回答解释说, --all需要重写所有分支。 如果您的回购中有标签 ,您需要清除所有这些以及分支,以便获得减小尺寸的好处,并且这需要额外的 - --tag-name-filter cat咒语。

虽然问题指定使用git filter-branch ,但提问者希望'从我的资源库中清除一些大型文件和目录',所以值得一提的是最好的工具实际上就是BFG Repo Cleaner ,它是一种更简单,更快速的替代方案git filter-branch 。 例如:

$ bfg --strip-blobs-bigger-than 10M

...删除所有大于10MB的斑点(不在您最新的提交中),并且可以在您的仓库中的所有分支和标签上运行。

充分披露:我是BFG Repo-Cleaner的作者。


我遵循所有的说明在我的Windows机器上这样做,但我一直得到一个错误,直到我停止使用单引号并改为使用双引号。

我的动机是我无意中检查了我的vagrant环境。 这是从所有分支中删除vagrant文件夹的命令:

git filter-branch --tree-filter "rm -rf vagrant" -f HEAD --all

用你的目录名替换vagrant ,它会从所有分支中删除这个目录。

链接地址: http://www.djcxy.com/p/46975.html

上一篇: branch on all branches

下一篇: Purging file from Git repo failed, unable to create new backup