命令来确定当前HEAD的上游引用? [英] command to determine the upstream ref of the current HEAD?
问题描述
我正在寻找我希望的简单的一行命令来确定当前签出分支的正确上游引用?
I'm looking for what I hope is the simple one line command to determine the the correct upstream ref for the currently checked out branch?
基本上类似于
git branch --remote HEAD
哪个(如果有效的话)会将符号模式HEAD转换为当前分支名称,然后选择 - remote
然后将其更改为远程跟踪分支的引用。 (但它不这样做!)
which (if it worked) would convert the symbolic pattern HEAD to the current branch name, and then the option --remote
then changes it to the ref of the remote-tracking branch. (But it doesn't do that!)
如果我的分支 morehelp
的配置为
remote = origin
merge = refs/heads/morehelp
简单的命令行会返回 refs / remotes / origin / morehelp
这是它的上游跟踪分支 git reset --hard< ref>
通过覆盖进行更新的情况)
The simple command line would return refs/remotes/origin/morehelp
which is it's upstream tracking branch (ideal for the git reset --hard <ref>
case of an update by overwrite)
推荐答案
我想你想
I think you want
git rev-parse --symbolic-full-name @{u}
@ {u}
是上游跟踪的缩写分支 HEAD
,该选项告诉 rev-parse
以您想要的格式打印它,而不是打印SHA提交ID。
@{u}
is the abbreviation for the upstream tracking branch of HEAD
and the option tells rev-parse
to print it in the format you want, rather than printing an SHA commit 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").
这篇关于命令来确定当前HEAD的上游引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!