101

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,030
  • 21
  • 100
  • 124
Shraddha
  • 2,177
  • 5
  • 16
  • 19

2 Answers2

181
git show <commit_id>

is the droid you are looking for, probably.

Ry-
  • 209,133
  • 54
  • 439
  • 449
Seth Robertson
  • 29,251
  • 6
  • 60
  • 53
  • 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
  • 2
    @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 - Reinstate Monica 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
22

@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
  • 32,739
  • 29
  • 126
  • 286