理解git push命令

8

我想要理解一个git命令。

在我的本地代码库中,我当前在master分支上。

我有一个名为origin的远程仓库,其中有两个分支:masterreview。 但是,我还有另一个名为review的远程仓库...

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

git push review

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

“我在Origin远程”这句话的意思不太清楚。你的本地代码库可能会将其他代码库列为其“远程”,但“在远程上”的说法并没有意义。 - jub0bs
2个回答

6
我明白这可能会让人感到困惑。你最好为你的分支和远程选择不同的名称。
当运行git push review时,实际上使用了以下语法。
git push <repository> [<refspec>...]

但你忽略了可选的<refspec>...参数。因此,在这里,git pushreview理解为远程而不是分支。所以,如果没有全部更新git push review将会把改动推送到名为review的远程。
这些更改将如何被推送呢?以下是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的详细信息,请参阅未指定分支的“git push”默认行为


0
你可以查看文档。

http://git-scm.com/docs/git-push

[<repository> [<refspec>...]]

首先是仓库(repository),然后是分支(branch)。但是如果不指定分支名称,它将采用您实际检出的分支的相同名称。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接