2017-08-09 18 views
3

この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を使用する必要がありますか?

答えて

7

これは、git branchgit pushを混合します。

git branchコマンドが既にNick's answerで与えられた理由のために、後者を支持して非難前者と、--set-upstream--set-upstream-to両方を有します。

git pushコマンドには、-u aka --set-upstreamという引数がありません。これは、プッシュが成功した場合、あなたのローカルGitは、あなたのソースとして提供されているブランチリファレンスの上流として、別のGitを設定した宛先ブランチに対応するリモートトラッキングブランチを設定しなければならないことを意味します。彼らのGitはちょうどブランチを作成しているので、自身のGitはリポジトリに作成しました。

$ git checkout -b newbranch 
... work, commit, etc 

origin/newbranchにその上流を設定したい:(!やれやれ)である

は、あなたが枝newbranchを作成したとします。しかし、あなたがしようとした場合、それは失敗します。

$ git branch --set-upstream-to=origin/newbranch 
error: the requested upstream branch 'origin/newbranch' does not exist 

originで他のgitがnewbranchという名前の枝を持っていないためorigin/newbranchは、まだ存在しませんので。

すぐに、しかし、あなたgit pushお近くのnewbranch自分のGitに、そのGitはnewbranchでのリポジトリを作成するようにします。今度は彼らがを実行するnewbranchをあなたのあなたのorigin/newbranchnewbranchを覚えて作成します。 今すぐを使用するとを使用できますが、git pushが自動的にそれを行うことができるといいかもしれません。それはgit push --set-upstream、別名-uです。

git branch --set-upstream-toに関連するですが、同じではありません。

+0

ああ、私の混乱を解消した。もう一度手伝ってくれてありがとう! – Thor

+0

MIne too!ありがとう。 – Nick

1

gitのバージョンによって異なります。 --set-upstream-toは1.7.12-1.7.13の期間に2012年に導入されました。それより新しいバージョンにはそれを含める必要があります。これは言っコミットするものである:

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-branch(1)のgit-2.7.5のマンページにはそれについては何の言及もなく、まだまだ残っています。あなたはちょっと注意する必要があります。

EDIT:申し訳ありませんが、それはb347d06bf097aca5effd07871adf4d0c8a7c55bdコミットで非推奨であるが、これらのコミットだけではないgit-pushgit-branchに言及。

+0

こんにちはニック、答えてくれてありがとう!私が尋ねることができるなら、あなたがあなたの答えで述べた特定のコミットを探していたときに、あなたの検索戦略は何か教えてください。 gitのgitリポジトリには何千ものコミットが含まれていますが、どのようにして自分が望むものを見つけることができますか? – Thor

+1

私は 'git log --grep = set-upstream-to'を実行し、最後のものを見ました(しかし、私は編集を必要とした最後のものを逃しました:-)) – Nick

+0

ああ、はい、忘れました正規表現について知らせてくれてありがとうございます。本当にそれを感謝します:) – Thor