git rev-parse是做什么的? [英] What does git rev-parse do?
问题描述
我已阅读手册页,但它提出了更多问题比答案。例如:
选取和按摩参数
按摩?这意味着什么?
我用作解析器(对SHA1)修订说明符,如
git rev-parse HEAD ^
或
git rev-parse origin / master
这是命令的目的吗?如果没有,甚至正确地使用它来实现这一目标? 解决方案
git rev-parse
是一个辅助管道 code> git rev-parse
一个常用的用法是打印SHA1哈希给出了修订说明符。此外,它还有多种选项来格式化输出,如 - short
用于打印较短的唯一SHA1。
还有其他的用例(在git之上构建的脚本和其他工具中),我用它:
-
- verify
来验证指定的对象是否为有效的git对象。 -
- git-dir
用于显示.git
目录的绝对/相对路径。 检查您目前是否正在使用- is-inside-git-dir
或者在使用的工作树内的仓库中 - is-inside-work-tree code>
- 使用
检查回购是否为空 - is-bare-repository
- 打印SHA1哈希分支(
- 分支
),标签(- tags
)和refs也可以基于远程过滤(使用- remote
) -
- parse-opt
标准化脚本中的参数(类似于getopt
)并打印一个输出字符串,可以使用eval
按摩
只是意味着可以将信息从一种形式转换为另一种形式,即转换命令。这些是我能想到的一些快速示例:
- 分支或标记名称到提交的SHA1指向的位置,以便它可以传递给只接受提交的SHA1值的管道命令。
- 修订范围
A..B
代表git log
或git diff
作为底层管道命令的等价参数,如B ^ A
- 修订范围
What does git rev-parse
do?
I have read the man page but it raised more questions than answers. Things like:
Pick out and massage parameters
Massage? What does that mean?
I'm using as a resolver (to SHA1) of revision specifiers, like
git rev-parse HEAD^
or
git rev-parse origin/master
Is this the command’s purpose? If not, is even correct to use it to achieve this?
git rev-parse
is an ancillary plumbing
command primarily used for manipulation.
One common usage of git rev-parse
is to print the SHA1 hashes given a revision specifier. In addition, it has various options to format this output such as --short
for printing a shorter unique SHA1.
There are other use cases as well (in scripts and other tools built on top of git) that I've used for:
--verify
to verify that the specified object is a valid git object.--git-dir
for displaying the abs/relative path of the the.git
directory.- 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 togetopt
) and print an output string that can be used witheval
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:
- 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.
- a revision range
A..B
forgit log
orgit diff
into the equivalent arguments for the underlying plumbing command asB ^A
这篇关于git rev-parse是做什么的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!