gpt4 book ai didi

git - 理解 git push 命令

转载 作者:太空狗 更新时间:2023-10-29 13:12:12 27 4
gpt4 key购买 nike

我正在尝试理解一个 git 命令。

在我的本地存储库中,我目前在 master 上。

我在一个名为 origin 的远程服务器上,其中有两个分支:masterreview。但是,我有另一个 Remote ,也称为 review...

我的问题是:当我运行以下命令时会发生什么?

git push review

它是否将更改推送到同一 Remote 上的 review 分支?还是将更改推送到名为 review 的另一个远程?

最佳答案

我明白这会让人感到困惑。您最好为您的分支和远程选择不同的名称。

运行时git push review ,您实际上是在使用以下语法

git push <repository> [<refspec>...]

但您要离开可选的 <refspec>...论证出来。因此,在这里,git push懂了review作为远程,而不是作为分支。所以git push review将推送更改(如果不是一切都是最新的)到您名为 review 的 Remote .

如何 push 这些变化?这是git-push的相关段落手册页:

When the command line does not specify what to push with
<refspec>... arguments or --all, --mirror, --tags options, the
command finds the default <refspec> by consulting remote.*.push
configuration, and if it is not found, honors push.default
configuration to decide what to push (See gitlink:git-config[1] for
the meaning of push.default).

那么当你运行 git push review 时会发生什么?取决于你的 Git 配置。运行

git config remote.review.push

如果找到匹配项,则相应的值将指示您运行 git push review 时发生的情况。 .如果未找到匹配项,Git 将使用 push.default 的值弄清楚该怎么做;运行

git config push.default

看哪个模式push.default目前在。有关什么的更多详细信息push.default确实,我推荐你Default behavior of "git push" without a branch specified

关于git - 理解 git push 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25913507/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com