119

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.

1
  • The -p can be useful here too. Commented Nov 15, 2012 at 15:40

3 Answers 3

206
git show <commit_id> 

is the droid you are looking for, probably.

Sign up to request clarification or add additional context in comments.

4 Comments

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: See stackoverflow.com/questions/2706797/… otherwise known as: git branch --contains <commit>
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.
This also shows the patch. So you have to to do git show <commit_id> --no-patch if you want to see the same look as git log
35

@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

Comments

6

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 ]

1 Comment

If you don't want to enter the interactive, vim-like UI and only want "raw" output: --oneline --no-patch

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.