Shraddha
Shraddha

Reputation: 2579

Look up commit log for commit ID in Git

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.

Upvotes: 116

Views: 182176

Answers (3)

Eduardo Lucio
Eduardo Lucio

Reputation: 2487

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 ]

Upvotes: 5

Noitidart
Noitidart

Reputation: 37328

@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

Upvotes: 35

Seth Robertson
Seth Robertson

Reputation: 31471

git show <commit_id>

is the droid you are looking for, probably.

Upvotes: 202

Related Questions