发布于 2017-08-09 13:35:42
这把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的分支。
然而,你很快就会将你的本地newbranch git push到他们的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相关,但并不相同。
发布于 2017-08-09 11:21:18
这取决于您的git版本。--set-upstream-to于2012年在1.7.12-1.7.13的时间范围内推出。任何比这更新的版本都应该包含它。这就是提交所说的:
commit 6183d826ba62ec94ccfcb8f6e3b8d43e3e338703
Author: Carlos Martín Nieto <cmn@elego.de>
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的git-branch(1)手册页在没有警告的情况下提到了它,这意味着它仍然存在,并将继续存在。你只要小心就行了。
编辑:对不起,它在提交b347d06bf097aca5effd07871adf4d0c8a7c55bd中已被弃用,但这些提交只提到了git-branch,没有提到git-push。
https://stackoverflow.com/questions/45580960
复制相似问题