8

現在チェックアウトされているブランチの正しいアップストリーム ref を特定するための単純な 1 行のコマンドを探しています。

基本的に次のようなもの

git branch --remote HEAD

これは (機能した場合) 記号パターン HEAD を現在のブランチ名に変換し、オプション--remoteはそれをリモート追跡ブランチの参照に変更します。(しかし、それはしません!)

の構成を持つブランチmorehelpがある場合

remote = origin
merge = refs/heads/morehelp

単純なコマンド ラインは、どちらが上流の追跡ブランチであるかを返します (上書きによる更新refs/remotes/origin/morehelpの場合に最適です)。git reset --hard <ref>

4

1 に答える 1

16

私はあなたが欲しいと思います

git rev-parse --symbolic-full-name @{u}

@{u}のアップストリーム追跡ブランチの省略形でHEADあり、オプションはrev-parse、SHA コミット ID を出力するのではなく、必要な形式で出力するように指示します。

からgit help rev-parse

   --symbolic
       Usually the object names are output in SHA1 form (with possible ^ prefix); this option makes them output in a form as close to the original
       input as possible.

   --symbolic-full-name
       This is similar to --symbolic, but it omits input that are not refs (i.e. branch or tag names; or more explicitly disambiguating
       "heads/master" form, when you want to name the "master" branch when there is an unfortunately named tag "master"), and show them as full
       refnames (e.g. "refs/heads/master").
于 2013-03-07T23:50:24.237 に答える