gpt4 book ai didi

git - 命令确定当前 HEAD 的上游 ref?

转载 作者:太空狗 更新时间:2023-10-29 12:50:26 24 4
gpt4 key购买 nike

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

本质上类似

git branch --remote HEAD

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

如果我有分支morehelp配置为

remote = origin
merge = refs/heads/morehelp

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

最佳答案

我觉得你想要

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").

关于git - 命令确定当前 HEAD 的上游 ref?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15284109/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com