Git Refspec可以包括多个通配符吗?



在我可以访问的存储库上运行 git ls-remote origin,我使用git namespaces看到以下形式的分支。

refs/namespaces/share/refs/namespaces/<username>/refs/heads/<branch-name>

我想将其映射到refs/remotes/<username>/<branch-name>

此GitHub帮助页面通过将其添加到.git/config

来求解如何解决此问题的更简单版本的示例
[remote "origin"]
    fetch = +refs/pull/*/head:refs/remotes/origin/pr/*

我可以使事情适合我的情况:

[remote "origin"]
    fetch = +refs/namespaces/share/refs/namespaces/USER1/refs/heads/<branch-name>:refs/remotes/origin/USER1/*
    fetch = +refs/namespaces/share/refs/namespaces/USER2/refs/heads/<branch-name>:refs/remotes/origin/USER2/*
    # etc

,但这要求我提前了解所有用户名。不幸的是,使用两个* S不起作用:

[remote "origin"]
    fetch = +refs/namespaces/share/refs/namespaces/*/refs/heads/<branch-name>:refs/remotes/origin/*/*

是否有实现此重新映射的方法?

否 - 或更确切地说,不短缺编写一系列fetch =行的程序。

您可以使用一种元配置编写这样的程序(存储在.git/config或其他地方,在此级别上并不重要)。该程序将在遥控器上运行git ls-remote,计算适当的fetch =行,然后更新.git/config以包含它们。

如果您将此程序命名为git-synchrofetch(此名称是为了回到Synchromesh),则可以在更新.git/config后将其调用git fetch。然后,您可以运行git synchrofetch origin而不是git fetch origin,以更新默认的获取然后获取。

(请注意,该程序也可以直接使用一组RefsPecs调用git fetch,但是这里的想法是让大多数其他GIT代码正常运行,并且只有当您认为一组用户时才进行重新同步名称已更改。)

最新更新