git push --set-upstream vs --set-upstream-to
根据此article,git push --set-upstream
已被弃用,应该使用git push --set-upstream-to
来代替。git push --set-upstream vs --set-upstream-to
但是当我检查git push文档时,我只能找到--set-upstream
,但--set-upstream-to
是没有在哪里可以找到。
那么--set-upstream
已弃用?我应该使用--set-upstream
还是--set-upstream-to
?
这混合了git branch
和git push
。
的git branch
命令有两种--set-upstream
和--set-upstream-to
,前者有利于后者在Nick's answer已经给出的理由的弃用。
git push
命令只有-u
又名--set-upstream
,它没有参数。这意味着如果推送成功,你的本地Git应该设置一个作为源的分支引用的上游,与目标分支相对应的远程跟踪分支,你可以设置另一个Git,在很多情况下,你的自己的Git刚刚在中创建了你的存储库,因为他们的Git也刚刚创建了他们的分支。 (唷!)
也就是说,假设你已经创建了一个分支newbranch
:
$ git checkout -b newbranch
... work, commit, etc
,并希望其上游设置为origin/newbranch
。但是,如果你尝试,它失败:
$ git branch --set-upstream-to=origin/newbranch
error: the requested upstream branch 'origin/newbranch' does not exist
因为origin/newbranch
还不存在,因为origin
其他Git并不有一个名为newbranch
分支。
很快,但是,你git push
当地newbranch
自己的Git,让自己的Git创建newbranch
在他们库。现在他们做有一个newbranch
,你的 Git创建你的origin/newbranch
记住他们的newbranch
。而现在你可以使用git branch --set-upstream-to
,但它可能很好,如果git push
可以自动做到这一点 - 这就是git push --set-upstream
,又名-u
,选项。
这是有关git branch --set-upstream-to
,但不一样。
这取决于你的git版本。 --set-upstream-to
于2012年7月1日至7月7日推出。任何比这更新的版本都应该包括它。这就是承诺说:
commit 6183d826ba62ec94ccfcb8f6e3b8d43e3e338703
Author: Carlos Martín Nieto <[email protected]>
Date: Mon Aug 20 15:47:38 2012 +0200
branch: introduce --set-upstream-to
The existing --set-uptream option can cause confusion, as it uses the
usual branch convention of assuming a starting point of HEAD if none
is specified, causing
git branch --set-upstream origin/master
to create a new local branch 'origin/master' that tracks the current
branch. As --set-upstream already exists, we can't simply change its
behaviour. To work around this, introduce --set-upstream-to which
accepts a compulsory argument indicating what the new upstream branch
should be and one optinal argument indicating which branch to change,
defaulting to HEAD.
The new options allows us to type
git branch --set-upstream-to origin/master
to set the current branch's upstream to be origin's master.
我会说这是不是很过时,但它是气馁。我不知道最近是否被弃用了,但事实上git-2.7.5的联机帮助页提到了它,但没有提出任何警告,这意味着它仍然存在,并且会留在身边。你只需要小心。
编辑:对不起,这是不赞成在提交b347d06bf097aca5effd07871adf4d0c8a7c55bd,但这些提交只提git-branch
,不git-push
。
啊,这清除了我的困惑。非常感谢您的帮助! – Thor
我也是!谢谢。 – Nick