2

I want to programmatically determine whether a commit is in the git current checkout or not.

I just need a nonzero exit status, not other output.

I found this work around:

git log | grep -q 5bbfb3512b0ab900a66f70104bd0e052a66a699a

But this does not work 100% reliable. There could be a commit message which contains the string "5bbfb...".

Is there a solution without unix pipe and grep?

guettli
  • 25,042
  • 81
  • 346
  • 663
  • Specifically, [this answer](https://stackoverflow.com/a/13526591/1615903). You would use HEAD as `` – 1615903 Aug 10 '17 at 09:04

1 Answers1

3

You can simply not output the message - do like so:

git log --format=format:%H | grep -q <sha1 here>
jimf
  • 4,527
  • 1
  • 16
  • 21