概要

Git:git-rev-parse 命令学习

博客

原帖收藏于IT老兵博客

前言

在研究Jenkins的时候,遇到了git rev-parse这个命令,这里学习一下这个命令。

正文

git-rev-parse - Pick out and massage parameters

这是这个命令的概要解释,理解起来有一点障碍,挑选出来并且“按摩”参数,这个有点意思啊,对参数进行一下按摩。(这里这个massage是不是应该按照调整来理解呢?)

Many Git porcelainish commands take mixture of flags (i.e. parameters that begin with a dash -) and parameters meant for the underlying git rev-list command they use internally and flags and parameters for the other commands they use downstream of git rev-list. This command is used to distinguish between them.

许多Git porcelainish命令(这个地方不知道怎么理解)会混合使用标志(即以短划线开头的参数-)以及参数,这些参数用于git rev-list它们在内部使用的基础命令,以及标志和参数用于其(git rev-list)下游使用的其他命令。这个命令用于区分它们。

看到这里,感觉这个命令好像只是为了鉴别这些参数是否用于git rev-list的,底下参考的stackoverflow的帖子说,这是一个辅助的探测(管道)工具。

git rev-parse is an ancillary plumbing command primarily used for manipulation.
–verify to verify that the specified object is a valid git object.

例如一些常见场景:
显示指定提交号的SHA1

$ git rev-parse 5a382c9
5a382c95394410bb716d92ee7418c8e3a17eb8c3

验证指定的对象是一个有效的git对象

$ git rev-parse --verify HEAD
a1498cc2435b5df53653279395dac42e14e1d393

–verify
Verify that exactly one parameter is provided, and that it can be turned into a raw 20-byte SHA-1 that can be used to access the object database. If so, emit it to the standard output; otherwise, error out.

这里会去通过HEAD去获取a1498cc2435b5df53653279395dac42e14e1d393,然后通过这个去访问对象的数据库。

显示git默认目录

$ git rev-parse --git-dir
.git

以下还有几项,不具体翻译了。

  • Checking if you’re currently within a repository using --is-inside-git-dir or within a work-tree using --is-inside-work-tree
  • Checking if the repo is a bare using --is-bare-repository
  • Printing SHA1 hashes of branches (–branches), tags (–tags) and the refs can also be filtered based on the remote (using --remote)
  • –parse-opt to normalize arguments in a script (kind of similar to getopt) and print an output string that can be used with eval

Massage just implies that it is possible to convert the info from one form into another i.e. a transformation command. These are some quick examples I can think of:

这里解释了Massage,Massage在这里暗示着有可能会把一个信息的格式转换成另外一种。

  • a branch or tag name into the commit’s SHA1 it is pointing to so that it can be passed to a plumbing command which only accepts SHA1 values for the commit.

把一个分支名或者tag名转换成了一个提交的SHA1,要是从这个意义来理解,这个plumbing还真是管道的意思。

  • a revision range A…B for git log or git diff into the equivalent arguments for the underlying plumbing command as B ^A

总结

这个命令有点绕,第一天完全没看懂,第二天才初步搞明白一点。

参考

https://git-scm.com/docs/git-rev-parse 官网
https://cloud.tencent.com/developer/section/1138781 这里有点意思,是对上面官网的直接翻译
https://stackoverflow.com/questions/15798862/what-does-git-rev-parse-do 这里讲了一些常见的用法

Git:git-rev-parse 命令学习相关推荐

  1. 浅谈Git原理和常用命令(学习笔记)

    因为多人和做的项目经常用Git但是对于git我总是不太理解,今天熬夜学习了一下 Git我们clone下来的项目的根目录下有一个 .git 的文件,这个不是我们的工作区,它叫做版本库,它来记录我们工作区 ...

  2. externalreferences 命令在 sdi 模式下不可用_一个适合新手交互式Git命令学习项目

    前言 在我们日常工作开发中,Git是必不可少的版本控制软件,很多时候我们都用Git来管理我们的项目. 比较常用的有Github,Gitlab,Stash等. 因此对于Git命令的掌握是我们工作必备的能 ...

  3. 史上最全Git命令学习:从基础出发,Java中高级面试题总结(全面)

    将暂存区的文件提交本地仓库: 将本地仓库的文件推送到远程仓库: Git文件的四种状态 根据一个文件是否已加入版本控制,可以把文件状态分为:Tracked(已跟踪)和Untracked(未跟踪),而tr ...

  4. Git常用命令学习手册

    注意: 学习前请先配置好Git客户端 相关文章:Git客户端图文详解如何安装配置GitHub操作流程攻略 官方中文手册:http://git-scm.com/book/zh GIT 学习手册简介 本站 ...

  5. Git版本控制软件结合GitHub从入门到精通常用命令学习手册

    GIT 学习手册简介 本站为 Git 学习参考手册.目的是为学习与记忆 Git 使用中最重要.最普遍的命令提供快速翻阅. 这些命令以你可能需要的操作类型划分,并且将提供日常使用中需要的一些常用的命令以 ...

  6. Git版本控制软件结合GitHub常用命令学习手册

    编程技术2015-1-16TECHUG1条评论 我们发布了很多Git相关的文章,有系列教程(<Pro Git系列>),也有各种独门绝技(<让你的Git水平更上一层楼的10个小贴士&g ...

  7. Git命令学习总结(-)

    入职的第一天,让git命令直接给难住了,汗!使用习惯可视化的工具对于命令行早就忘记的一干二净.还好,回家自己练习一下,总会没有错的.git就不做简介了,版本管理除了svn就是git了,其他的都无所谓了 ...

  8. 【Git学习记录】git查询历史版本记录命令

    文章目录 一.git查询历史版本记录命令 1. 详细显示历史记录 2.简洁显示历史记录 3.标题显示更多信息 二.git前进后退版本操作 1. 基于索引值操作[推荐] 2.使用^符号: 只能后退 3. ...

  9. GIT 命令学习:获取与创建项目

    GIT命令 获取和创建命令 init init主要是用来创建一个git库或者重新初始化一个已经存在的库.这个命令会 创建一个.git目录,其中会包含objects.refs/heads.refs/ta ...

最新文章

  1. Google综述:细数Transformer模型的17大高效变种
  2. [处理器、单片机]ARM
  3. 一个极好的ALV例子
  4. 敢问路在何方——项目经理成长手记
  5. Python 3.10刚发布,这5点非常值得学习!
  6. 事物Spring boot @Transactional
  7. 水性油墨在纺织品印花中的应用
  8. 电子邮件验证及部分常用正则表达式
  9. CEFSharp崩溃分析及解决办法
  10. 手持式频谱分析仪/路测仪推荐哪一款?TFN全新RMT系列不容错过
  11. silktest 破解 转帖未验证
  12. android模拟器无法上局域网,模拟器无法上网解决方法
  13. 世界地图的制作(总体概念设计)
  14. 腾讯大王卡、天王卡代申请
  15. Qt 加载图片文件路径详解
  16. C语言项目案例分析 源代码
  17. Android 开发之Okhttp网络请求日志打印
  18. 【C语言典例】——day7:尼科彻斯定理
  19. Office2010 下载
  20. 常见的Quad-SPI引脚含义

热门文章

  1. 经典红白机游戏音乐。
  2. 《趣谈网络协议》(刘超老师)读后笔记记录 003
  3. java利用Freemarker模板生成格式友好的doc或者docx文档
  4. D-1.7.18 解决安装Anaconda时遇到的困难的收获与思考
  5. win7系统下samba服务器无法登陆,win7系统访问NAS/Samba服务器失败的解决方法
  6. Python实现牛顿迭代法
  7. 平均绝对误差的MATLAB怎么写,标准差、均方误差、均方根误差、平均绝对误差
  8. ABAQUS材料子程序学习(20年12月1日)
  9. 欢聚时代c++开发岗位面试经验
  10. 基于Debian的SteamOS 2.154稳定版发布