首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >git推送--set-upstream vs --set-upstream-to

git推送--set-upstream vs --set-upstream-to
EN

Stack Overflow用户
提问于 2017-08-09 10:57:57
回答 2查看 27.1K关注 0票数 16

根据此articlegit push --set-upstream已弃用,应该使用git push --set-upstream-to

但是当我查看git push文档时,我只能找到--set-upstream,但--set-upstream-to却找不到。

那么--set-upstream被弃用了吗?我应该使用--set-upstream还是--set-upstream-to

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-08-09 13:35:42

这把git branchgit push混在了一起。

git branch命令同时具有--set-upstream--set-upstream-to,由于Nick's answer中已经给出的原因,前者不推荐使用,而支持后者。

git push命令只有-u,也就是--set-upstream,它不带参数。这意味着如果推送成功,您的本地Git应该将远程跟踪分支设置为作为源提供的分支引用的上游,该分支对应于您让另一个Git设置的目标分支,在许多情况下,您自己的Git刚刚在您的存储库中创建了分支,因为他们的Git也刚刚创建了他们的分支。(呼!)

也就是说,假设您已经创建了一个分支newbranch

代码语言:javascript
复制
$ git checkout -b newbranch
... work, commit, etc

并希望将其上游设置为origin/newbranch。但是如果你尝试了,它就失败了:

代码语言:javascript
复制
$ 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相关,但并不相同。

票数 31
EN

Stack Overflow用户

发布于 2017-08-09 11:21:18

这取决于您的git版本。--set-upstream-to于2012年在1.7.12-1.7.13的时间范围内推出。任何比这更新的版本都应该包含它。这就是提交所说的:

代码语言:javascript
复制
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

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45580960

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档