【问题标题】:command to determine the upstream ref of the current HEAD?命令来确定当前 HEAD 的上游参考?
【发布时间】:2013-02-23 09:56:04
【问题描述】:

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

基本上类似

git branch --remote HEAD

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

如果我的分支 morehelp 配置为

remote = origin
merge = refs/heads/morehelp

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

【问题讨论】:

    标签: git git-branch


    【解决方案1】:

    我想你想要

    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 rev-parse --symbolic-full-name HEAD 使用一些不起作用的远程选项。感觉应该更明显。 (即使@{u} 带有注释“缺少的引用默认为当前分支。)。
    • “感觉应该更明显。” 但这是 Git,所有真正有用的命令都非常不明显;)
    • +100(b;-) 为此。当我通过我的 Github 存储库在机器之间传递我的私人开发分支之一时,我一直在考虑将 --to-usptream 添加到 git reset --hard <ref> 以重置上游案例。现在我可以使用你的单线创建一个别名。
    • 事实上git reset --hard @{upstream} 是删除本地提交的正确命令,并更改为分支上游存储库的最后一次获取的提交。非常适合在机器之间传输个人变基(例如 windows Linux 传输)
    猜你喜欢
    • 1970-01-01
    • 2020-12-30
    • 1970-01-01
    • 2020-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多