tor*_*rek 19
这混淆了git branch和git push.
由于Nick的答案中已经给出的原因,该git branch命令有两个--set-upstream并且--set-upstream-to前者因后者而被弃用.
该git push命令只有-uaka --set-upstream,不带参数.这意味着如果推送成功,您的本地Git应该设置作为源的分支引用的上游,对应于您获得另一个Git设置的目标分支的远程跟踪分支,在许多情况下,您的刚刚在你的存储库中创建了自己的Git,因为他们的Git也刚刚创建了他们的分支.(呼!)
也就是说,假设您已经创建了一个分支newbranch:
$ git checkout -b newbranch
... work, commit, etc
Run Code Online (Sandbox Code Playgroud)
并希望将其上游设置为origin/newbranch.但如果你尝试,它会失败:
$ git branch --set-upstream-to=origin/newbranch
error: the requested upstream branch 'origin/newbranch' does not exist
Run Code Online (Sandbox Code Playgroud)
因为origin/newbranch 还不存在,因为其他git at origin没有名为的分支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 年在 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.
Run Code Online (Sandbox Code Playgroud)
我会说它并没有被完全弃用,但它是不鼓励的。我不知道它最近是否被弃用,但事实上git-branch(1)git-2.7.5的联机帮助页在没有警告的情况下提到了它,这意味着它仍然存在并且将继续存在。你只需要小心。
编辑:对不起,它在提交 b347d06bf097aca5effd07871adf4d0c8a7c55bd 中被弃用,但这些提交只提到git-branch,而不是git-push。