代码之家  ›  专栏  ›  技术社区  ›  LightCC

我可以根据URL为Git repo使用不同的作者信息吗

  •  2
  • LightCC  · 技术社区  · 8 年前


    作为比较,我能够根据URL成功地设置不同的代理信息,如下所示:

    git config --global http.https://github.com.proxy http://<myworkproxy:port>
    git config --global https.https://github.com.proxy http://<myworkproxy:port>
    

    只有在以下情况下才会使用代理 https://github.com 在远程URL中。

    这可以通过输入一个真实的远程URL进行验证,如下所示,Git将弹出要使用的代理:

    git config --url-match https.proxy https://github.com/<rest of repo URL>
    

    因此,我尝试了上述方法 user.name user.email 也:

    git config --global user.https://github.com.name <My Github.com user name>
    git config --global user.https://github.com.email <My Github.com user email>
    

    这将检查我的全局配置文件(使用 git config --global -e 要在编辑器中打开它),所有内容似乎都已正确设置:

    [user]
        name = <My work user name>
        email = <My work user email>
    [user "https://github.com"]
        name = <My github.com user name>
        email = <My github.com user email>
    

    即使我使用 git config --url-match user.name https://github.com/<rest of repo URL>

    然而,当我使用git提交时(无论是从GUI还是直接在命令行上),它仍然总是使用我的工作 使用者电子邮件

    URL是否可以全局匹配用户名和电子邮件?还是我做错了什么?

    谢谢

    1 回复  |  直到 8 年前
        1
  •  3
  •   bk2204    8 年前

    git不允许您使用URL匹配来设置 user.name user.email 设置。

    URL匹配通常限于涉及与远程服务器交互的设置,例如 http.* credential.* 设置。如果你跑步 git config --help <url> 组成部分

    原因是git在设置非远程设置时不考虑克隆或推送URL。

    但是,您可以按存储库设置这些值。如果要自动执行此操作,可以在克隆时通过使用适当的配置文件设置模板目录进行设置(请参见 git init --help --template 克隆时的选项。如果愿意,可以将其推送到别名中。