110

I want to look at a commit by ID. For instance, I want to know the code that got committed for that ID, something like:

git log <commit_id>

And this would display the committed code and commit message that corresponds to this ID.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Shraddha
  • 2,427
  • 5
  • 17
  • 21

3 Answers3

191
git show <commit_id>

is the droid you are looking for, probably.

Ry-
  • 218,210
  • 55
  • 464
  • 476
Seth Robertson
  • 30,608
  • 7
  • 64
  • 57
  • How can I find the name of the branch in which is the commit I'm looking for? I can see just commit ID, Author, Date and diff of the commit. But I can't find the name of the branch where the commit can be found. – Vojta Aug 27 '18 at 13:07
  • 3
    @Vojta: See https://stackoverflow.com/questions/2706797/finding-what-branch-a-git-commit-came-from otherwise known as: `git branch --contains ` – Seth Robertson Aug 28 '18 at 17:44
  • 1
    Actually you need to put two dashes after the commit id: `git show XXXX --` It is required to differentiate between a file and a commit ID. – Tomáš Zato Oct 02 '18 at 14:11
  • This also shows the patch. So you have to to do `git show --no-patch` if you want to see the same look as `git log` – Noitidart Dec 08 '18 at 17:36
29

@SethRobertson's solution works for me but it shows a diff. I wanted to see it exactly like git log shows it. So add --no-patch:

git show <commit_id> --no-patch

I learned this from - https://stackoverflow.com/a/31448684/1828637

Noitidart
  • 35,443
  • 37
  • 154
  • 323
0

Search for commits in repository history

Search commit by message

MODEL

git log --all --grep='<MENSAGE_CONTENT>'

EXAMPLE

git log --all --grep='Merge pull request #240'

Search commit by hash

MODEL

git show <COMMIT_HASH> --no-patch
git show <COMMIT_HASH_PART> --no-patch

EXAMPLE

git show b8c3fd58a0db675a6d9b9e819419f6ebc967278a --no-patch
git show b8c3fd5 --no-patch

[Ref(s).: https://stackoverflow.com/a/7124949/3223785 , https://stackoverflow.com/a/53685160/3223785 ]

Eduardo Lucio
  • 1,771
  • 2
  • 25
  • 43