2

考虑以下存储库。它有很多用于团队成员的私有分支,都在refs/heads/team/命名空间下,我不想获取,但我仍然想获取所有其余部分,包括该team命名空间之外的任何可能新创建的分支。

$ git ls-remote http://gerrit.asterisk.org/asterisk refs/heads/* | wc -l
217
$ git ls-remote http://gerrit.asterisk.org/asterisk refs/heads/* | grep -v refs/heads/team/ | wc -l
32

我正在获取fetch = +refs/heads/*:refs/remotes/golden/*,但这些私有分支只是压倒了我的refs/remote/golden命名空间,使其更难概览,并且还需要更多空间用于本地存储库。

是否可以获取refs/heads/*但排除refs/heads/team/*

4

1 回答 1

4

抱歉不行。

幸运的是,您可以任意接近,特别是如果您愿意每次都使用两次 fetch 或 fetch 之后再删除一次(可能这实际上会更有效,或者至少更省时;它可能需要更多的空间,取决于有多少对象最终变得无用)。

git ls-remote本质上,这里的想法是通过首先运行然后进行自己的过滤和重写fetch =远程条目(嗯,条目)来列出要采取的所有内容:

git ls-remote "$remote" 'refs/heads/*' |
    (git config --unset-all "remote.$remote.fetch";
     while read hash ref; do
        case $ref in refs/heads/team/*) continue;; esac
        rmtref="refs/remotes/$remote/${ref#refs/heads/}"
        git config --add "remote.$remote.fetch" "+$ref:$rmtref"
     done)
git fetch "$remote"

(添加一些前端工作以$remote适当设置)。使这项工作的关键是 git 结合然后遵守所有fetch =

对于另一个想法,运行一个正常的 ( +refs/heads/*:refs/remotes/...) 获取,然后运行一系列git update-ref -d refs/remotes/$remote/${ref#refs/heads/}与不需要的形式匹配的 for refs。如果您愿意,可以在之后加入(或和/或修剪)以缩小存储库git gcgit repack

于 2016-04-22T08:57:44.393 回答