2017-08-14 36 views
0

我想做如何引用其提交消息包含某個單詞的最新git提交?

$ git log - 5 
* adc24eb Jim > (HEAD -> demo) fixup 
* cb6a1a7 Jim > fixup 
* 60d7150 Jim > (origin/demo) Much prettier demo output. 
* a8112c2 Michael > Complete ugly demo: 

,然後做一些操作與a8112c2。而不是引用由SHA承諾,如

$ git <command> a8112c2 

,我要型喜歡的東西

$ git rebase -i %ugly 
$ git show %ugly 
$ git reset --soft %ugly 

其中%醜陋由混帳擴展到最近的SHA提交其第一個提交信息行包含單詞「醜陋」。

這是什麼神奇的語法?

我99%確定這已被問及之前,我無法找到它。

回答

4

man git-rev-parse是你的朋友。它看起來像你想:

:/<text>, e.g. :/fix nasty bug 
     A colon, followed by a slash, followed by a text, names a commit 
     whose commit message matches the specified regular expression. This 
     name returns the youngest matching commit which is reachable from 
     any ref. The regular expression can match any part of the commit 
     message. To match messages starting with a string, one can use e.g. 
     :/^foo. The special sequence :/! is reserved for modifiers to what 
     is matched. :/!-foo performs a negative match, while :/!!foo 
     matches a literal ! character, followed by foo. Any other sequence 
     beginning with :/! is reserved for now. 

因此,例如:

git show :/ugly 
+0

或者,更直接,[gitrevisions(7)(https://www.kernel.org/pub/software/scm /git/docs/gitrevisions.html) – torek

相關問題