命令确定当前HEAD的上游引用?

Phi*_*ley 8 git git-branch

我正在寻找我希望的简单的一行命令来确定当前检出的分支的正确上游引用?

基本上是这样的

git branch --remote HEAD

哪个(如果有效)将符号模式HEAD转换为当前分支名称,然后该选项--remote将其更改为远程跟踪分支的ref.(但它没有那样做!)

如果我有morehelp一个配置的分支

remote = origin
merge = refs/heads/morehelp
Run Code Online (Sandbox Code Playgroud)

简单的命令行将返回refs/remotes/origin/morehelp它的上游跟踪分支(适用于git reset --hard <ref>通过覆盖更新的情况)

Jon*_*ely 15

我想你想要的

git rev-parse --symbolic-full-name @{u}
Run Code Online (Sandbox Code Playgroud)

@{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").
Run Code Online (Sandbox Code Playgroud)

  • _"感觉就像是应该更明显的东西."_但这是Git,所有非常有用的命令都是非常明显的;) (2认同)