How can I show what a commit did? – Dev

The best answers to the question “How can I show what a commit did?” in the category Dev.

QUESTION:

A stupid way I know is:

git diff commit-number1 commit-number2

Is there a better way?

I mean, I want to know the commit1 itself. I don’t want to add the commit2 before it as a parameter.

ANSWER:

Does

$ git log -p

do what you need?

Check out the chapter on Git Log in the Git Community Book for more examples. (Or look at the the documentation.)

Update: As others (Jakub and Bombe) already pointed out: although the above works, git show is actually the command that is intended to do exactly what was asked for.

ANSWER:

git show <commit-id>

Documentation for git show

ANSWER:

I found out that “git show –stat” is the best out of all here.

It gives you a brief summary of the commit and what files you added and modified without giving you whole bunch of stuff, especially if you changed a lot files.

ANSWER:

TL;DR

git show <commit>


Show

To show what a commit did with stats:

git show <commit> --stat

Log

To show commit log with differences introduced for each commit in a range:

git log -p <commit1> <commit2>

What is <commit>?

Each commit has a unique id we reference here as <commit>. The unique id is an SHA-1 hash – a checksum of the content you’re storing plus a header. #TMI

If you don’t know your <commit>:

  1. git log to view the commit history

  2. Find the commit you care about.