git log of a single revision
Asked Answered
E

4

221

I have a commit c. I want to get the changeset of that exact commit c + metainformation and no other one. Is there a simpler way than git log -p c^..c to do that?

Elvia answered 2/11, 2010 at 21:10 Comment(0)
L
343

You can use show:

git show commit_id
Lafleur answered 2/11, 2010 at 21:20 Comment(1)
And git show defaults to HEAD as commit_id, so git show by itself shows the single most recent commit for your current branch.Aspersorium
W
74

Michal Trybus' answer is the best for simplicity. But if you don't want the diff in your output you can always do something like:

git log -1 -U c

That will give you the commit log, and then you'll have full control over all the git logging options for your automation purposes. In your instance you said you wanted the change-set. The most human-readable way to accomplish that would be:

git log --name-status --diff-filter="[A|C|D|M|R|T]" -1 -U c

Or, if you're using a git version greater than 1.8.X it would be:

git log --name-status --diff-filter="ACDMRT" -1 -U c

This will give you results similar to:

commit {c}
Author: zedoo <[email protected]>
Date: Thu Aug 2 {time-stamp}

   {short description}
D    zedoo/foo.py
A    zedoo/bar.py

Of course you can filter out whichever events you see fit, and format the return as you wish via the traditional git-log commands which are well documented here.

Wellturned answered 3/8, 2012 at 16:1 Comment(6)
If you don't want the diff, do git show --name-only <sha1>!Kalpak
If you just don’t want the diff, use git show -s <commit>.Protuberate
What does -1 do? Where is it documented?Coati
@Coati See the output of git help log under the "Commit Limiting" section. Or see git-scm.com/book/en/v2/… -<number> limits the number of commits to output.Chloric
If you don't want the diff but list of files changed, another way to do git show --stat <commit>Zeniazenith
In addition to @dbn's comment and @moeffju's comment, you can also use git log -1 <commit>Tibiotarsus
M
18

git log -p c -1 does just that .

Mayst answered 2/11, 2010 at 21:18 Comment(3)
What does -1 do? Where is it documented?Coati
@alex: The "-1" limits the number of displayed entries to the given number, it's short-hand for -n 1 or --max-number=1 and is documented here.Nympholepsy
Output is precisely the same as git show $sha for me on git v2.37.3.Parboil
A
0

You can use to filter change by description of commit:

git log --grep='part_of_description' -p

where git log --grep='part_of_description' select the commits that contains 'part_of_description' and -p show the changeset of each commit

Amar answered 15/1, 2020 at 16:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.