博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
获取默认值_Git获取本地分支对应的远端服务器分支名
阅读量:4357 次
发布时间:2019-06-07

本文共 1315 字,大约阅读时间需要 4 分钟。

4cb312cbcc1929c72aaef1f5361a716c.png

在 git 中,可以使用下面命令查看本地分支在远端服务器的分支名:

$ git rev-parse --abbrev-ref local_branch_name@{upstream}

把 local_branch_name 换成要查询的本地分支名,例如 master 等。下面通过例子来说明这个命令各个参数的含义。

先创建一个新的本地分支,名为 new_local_branch,关连到远端服务器的 Remote_Branch_U 分支:

$ git checkout -b new_local_branch aosp/Remote_Branch_UBranch new_local_branch set up to track remote branch Remote_Branch_U from aosp.Switched to a new branch 'new_local_branch'

查看本地分支 new_local_branch 在远端服务器的分支名:

$ git rev-parse --abbrev-ref new_local_branch@{upstream}aosp/Remote_Branch_U

如果所给的本地分支名没有关连到远端服务器分支,会打印报错信息:

$ git rev-parse --abbrev-ref great@{upstream}fatal: No upstream configured for branch 'great'

注意:@{upstream} 这一整串本身是命令的一部分,直接输入即可,不是要把 upstream 或者 {upstream} 替换成远端服务器仓库名。查看 man git-rev-parse 有如下说明:

@{upstream}, e.g. master@{upstream}, @{u}

The suffix @{upstream} to a branchname (short form @{u}) refers to the branch that the branch specified by branchname is set to build on top of. A missing branchname defaults to the current one.

即,@{upstream} 可以缩写为 @{u}如果不提供分支名,默认用当前本地分支名。

另外,如果不加 --abbrev-ref 选项,会打印分支head的hash值,而不是打印分支名。

$ git rev-parse --abbrev-ref new_local_branch@{u}aosp/Remote_Branch_U$ git rev-parse --abbrev-ref @{u}aosp/Remote_Branch_U$ git rev-parse @{u}66355f171f5ba7dbc66465e761b97afe2395b06e

这个命令可在shell脚本中自动获取到远端服务器分支名,而不是只能用默认值、或者要手动输入分支名,方便自动化处理。

转载地址:http://foxys.baihongyu.com/

你可能感兴趣的文章
GridView下DropDownList 的选择方法onselectedindexchanged 实现方法
查看>>
Python之set集合
查看>>
Generic Repository Pattern - Entity Framework, ASP.NET MVC and Unit Testing Triangle
查看>>
Win7 下新版本Windows Virtual PC 安装SharePoint步骤详解
查看>>
SQLSERVER 升级版本的方法
查看>>
正则表达式基本语法详解
查看>>
BZOJ2132: 圈地计划
查看>>
PHP数据库连接mysql与mysqli的区别与用法
查看>>
char * 与char []探究理解
查看>>
QT窗体显示在屏幕中间位置
查看>>
emmet使用技巧
查看>>
RPC-Thrift(二)
查看>>
MSSQL for Linux 安装指南
查看>>
【Golang 接口自动化08】使用标准库httptest完成HTTP请求的Mock测试
查看>>
洛谷 P1036 选数
查看>>
女性社区TOP10
查看>>
BP神经网络算法推导及代码实现笔记zz
查看>>
前端必读:浏览器内部工作原理
查看>>
每天一个Linux命令(16)--which命令
查看>>
libevent文档学习(一)多线程接口和使用
查看>>