有没有什么办法从它的消息中获得提交的SHA? [英] Is there any way to get the SHA of a commit from its message?
问题描述
当做一个 git标签
时,我并不总是记得HEAD〜6(例如)是包含还是独占。
鉴于我的大部分提交都带有问题编号,我想知道是否有一些神奇的命令从其消息的一部分搜索提交SHA。 p>
我知道很容易做一个 git log
并从那里开始工作,但我想要更简单:)
您可以使用:/ blah
$ b
<$
$ b例如, c $ c> git show:/ Issue#299
用过的。例如
git cherry-pick:/ Issue#299
如果您确实需要提交的SHA-1,则可以使用rev-parse。
git rev-parse:/ Issue#299
冒号,后跟斜杠,后跟文本 :
这个名称表示提交消息以指定文本开始的提交。
该名称返回可从任何ref访问的最新匹配提交。
If提交消息以!
开始,您必须重复该操作;特殊序列:/!
,紧接着是!
以外的其他内容。
When doing a git tag
, I'm not always great at remembering if HEAD~6 (for example) is inclusive or exclusive.
Given that most of my commits are prefixed with an issue number, I wondered if there is some magic command for searching for the commit SHA from part of its message.
I know it's easy to do a git log
and work from there, but I want more easy :)
EDIT : Someone also asked the opposite question: In Git, is there a way to get the "friendly" name for an arbitrary commit?
You can use :/blah
syntax to specify a commit whose commit message starts with the given text.
E.g.
git show ":/Issue #299"
This is valid anywhere a commit can be used. E.g.
git cherry-pick ":/Issue #299"
If you actually need the SHA-1 of the commit you can just use rev-parse.
git rev-parse ":/Issue #299"
See the "SPECIFYING REVISIONS" section of the git rev-parse man page:
A colon, followed by a slash, followed by a text:
This names a commit whose commit message starts with the specified text.
This name returns the youngest matching commit which is reachable from any ref.
If the commit message starts with a!
, you have to repeat that; the special sequence:/!
, followed by something else than!
is reserved for now.
这篇关于有没有什么办法从它的消息中获得提交的SHA?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!