【问题标题】:git config: "remote.origin.push" vs "push.default"git config:“remote.origin.push”与“push.default”
【发布时间】:2013-10-30 12:53:02
【问题描述】:

下面的命令怎么做:

git config remote.origin.push refs/heads/master:refs/heads/master

与以下命令有关:

git config push.default <option>

(使用--local--global 选项)

&lt;option&gt; 是其中之一:

nothing
matching
upstream (formerly tracking)
current
simple

?

我想我理解第二个配置命令,但我不明白第一个命令条件/与第二个命令的关系。以下是一些提供此问题背后背景的参考资料:

【问题讨论】:

    标签: git


    【解决方案1】:

    当你运行时:

    git push origin ...
    

    remote.origin.push 中设置的内容会覆盖push.default 中设置的内容。更一般地说,如果 remote.<em>name</em>.push 没有设置(这里 nameorigin),git 会退回到 push.default,然后如果也没有设置,它会退回到链接中描述的内置默认值。

    (Edit:Breaking Benjamin's comment below 和我的回复中所述,如果有 ... 部分包含至少一个 refspec,则 refspec 将覆盖remote.origin.push。所以remote.origin.push 仅适用于您在命令行上显式或隐式命名origin 并且 也省略命令行上的所有引用规范。例如,git push 与没有发现origin 的参数,或者没有其他参数的git push origin,Git 会查找您的remote.origin.push 设置并使用它;但git push origin xyz 使用您的remote.origin.push 设置。当然上面的... 部分可以包含更多的标志,所以此时正确的问题是... 部分是否包含任何refspecs。)

    注意:

    git config --local na.me value
    

    与没有--local 的含义相同。设置值时(如此处),--local--global--file <em>filename</em> 选项控制设置值的位置,但 --local 是默认值。

    (获取值时:

    git config na.me
    

    [或git config --getgit config --get-allgit config --get-regexp],--local 等选项限制了 git 将从何处读取,如果没有它,它会从 所有 中读取,如果在多个地方设置了某些内容,则“最本地化”会覆盖“不太本地化”。)

    【讨论】:

    • 谢谢! - 当您说git push origin ... 时,... 将是分支名称(如果提供),对吗?
    • 是(或任意参考规范,例如,refs/tags/foo:refs/deleteme 等)。
    • @torek ,如果我提到了git push origin branchName ,那么它将被解析为git push origin branchName:refs/heads/branchName。那么remote.origin.push 将如何出现在图片中?
    • git push 文档指出,remote.&lt;remote&gt;.push 仅在您运行 git push &lt;remote&gt; 而没有 &lt;refspec&gt; 部分时才起作用。如果您确实提供&lt;refspec&gt; 部分,则空的目标部分意味着重复源部分。但是请注意,git push origin xyzxyz 部分中的 unqualified 引用不一定会转换为 branch 名称。我不清楚的一件事是它在所有情况下确实如何翻译(例如,如果你有一个分支xyz 和一个标签xyz,但遥控器只有一个标签xyz) .
    猜你喜欢
    • 2012-08-06
    • 1970-01-01
    • 2012-11-29
    • 2014-07-18
    • 2015-10-23
    • 1970-01-01
    • 2017-01-12
    • 1970-01-01
    相关资源
    最近更新 更多