1

The command git log -1 gives information about the last commit. I am only interested in the number id. Can git give me this, or do I have to use basic parsing on the output (I know how to do that)?

> git log -1
commit abcdefgh123456789000 (HEAD -> master, origin/master)
Author: ...
...
projetmbc
  • 1,332
  • 11
  • 26

1 Answers1

7

Try using rev-parse:

git rev-parse HEAD
Ryan
  • 1,053
  • 12
  • 21
  • That is prettier than the solution given in the link of 0stone0. – projetmbc Aug 09 '21 at 13:11
  • 2
    [Should I answer duplicate questions?](https://meta.stackexchange.com/questions/10841/how-should-duplicate-questions-be-handled). The `git rev-parse HEAD` is [already mentioned](https://stackoverflow.com/a/53541370/5625547) in the marked duplicate. – 0stone0 Aug 09 '21 at 13:11
  • 1
    @projetmbc A marked question doesn't mean you should blindly copy paste the first answer, but take a look at the other answers, this one is already mentioned there. Please upvote there to let other people know you prefer that solution. – 0stone0 Aug 09 '21 at 13:12
  • @0stone0 I have not noticed it. ;-) – projetmbc Aug 09 '21 at 13:15