有没有什么办法从它的消息中获得提交的SHA? [英] Is there any way to get the SHA of a commit from its message?

查看:146
本文介绍了有没有什么办法从它的消息中获得提交的SHA?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当做一个 git标签时,我并不总是记得HEAD〜6(例如)是包含还是独占。

鉴于我的大部分提交都带有问题编号,我想知道是否有一些神奇的命令从其消息的一部分搜索提交SHA。 p>

我知道很容易做一个 git log 并从那里开始工作,但我想要更简单:)

917102 / in-git-is-there-a-way-to-get-the-friendly-name-for-an-arbitrary-commit>在Git中,有没有办法让一个任意的友好名称提交?

解决方案

您可以使用:/ blah

$ b

 <$ 
$ b

例如, c $ c> git show:/ Issue#299

用过的。例如

  git cherry-pick:/ Issue#299

如果您确实需要提交的SHA-1,则可以使用rev-parse。

  git rev-parse:/ Issue#299

指定修订混帐转第-parse man page


冒号,后跟斜杠,后跟文本

这个名称表示提交消息以指定文本开始的提交。

该名称返回可从任何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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆