我想你想要
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").