8

Is it possible to get the hash of a commit from a commit message?

I ran the following git log | grep tap and got a list of commit messages only, no hashes.

I need to cherry-pick a few of the listed commits, but don't want to manually search for them all to find the commit hashes.

CodeWizard
  • 128,036
  • 21
  • 144
  • 167
some_id
  • 29,466
  • 62
  • 182
  • 304

1 Answers1

11

Yep you can.

You have minor mistake in your command:
The correct command is to use the --grep as flag to the log and not as a unix command after the pipe |

git log --grep=".. any text you need to find ..."

enter image description here


git log --grep=<pattern>

Limit the commits output to ones with log message that matches the specified pattern (regular expression).

With more than one --grep=<pattern>, commits whose message matches any of the given patterns are chosen (but see --all-match).

When --show-notes is in effect, the message from the notes is matched as if it were part of the log message.

Community
  • 1
  • 1
CodeWizard
  • 128,036
  • 21
  • 144
  • 167
  • 1
    very good answer! I dont have the problem but now I am smarter. – Rubinum Mar 07 '16 at 09:23
  • Thank you, Here are some other great answers which you can learn from: http://stackoverflow.com/questions/34519665/how-to-move-head-checkout-revert-reflog-reset/34519716#34519716 http://stackoverflow.com/questions/35400416/what-are-some-more-forceful-ways-than-a-gitignore-to-keep-force-files-out-of/35400472#35400472 – CodeWizard Mar 07 '16 at 09:25