gpt4 book ai didi

git - 有没有办法从消息中获取提交的 SHA?

转载 作者:IT王子 更新时间:2023-10-29 00:45:02 25 4
gpt4 key购买 nike

在执行 git 标记 时,我并不总是善于记住 HEAD~6(例如)是包含还是排除。

鉴于我的大部分提交都以问题编号为前缀,我想知道是否有一些神奇的命令可以从其部分消息中搜索提交 SHA。

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

编辑:有人也问了相反的问题:In Git, is there a way to get the “friendly” name for an arbitrary commit?

最佳答案

您可以使用 :/blah 语法来指定其提交消息以给定文本开头的提交。

例如

git show ":/Issue #299"

这在任何可以使用提交的地方都有效。例如

git cherry-pick ":/Issue #299"

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

git rev-parse ":/Issue #299"

参见 "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.

关于git - 有没有办法从消息中获取提交的 SHA?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3003554/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com