Recent chats
ASKGEEZ Q&A GUIDETechnology & devices

How can I inspect exactly what changed in a particular Git commit?

Quick answer

Run git show <commit> to see the chosen commit’s message and textual diff. For a compact path summary, use git show --stat --name-status <commit>. These show the commit’s recorded changes, not necessarily the files’ current contents. Use git diff <commit> to compare that commit with the working tree, or name two commits to compare them with each other. [S1] [S2]

LET’S WORK THROUGH IT

The question, the details, the next step.

Question

I need to review one particular commit without changing any files. What should I run, and how do I make sure I’m looking at that commit rather than whatever happens to be in my working tree?

Geez

Run git show <commit>, replacing <commit> with the identifier you want to inspect. For example:

git show abc1234

Git displays that commit’s log message and textual diff. The diff shows recorded changes, rather than simply showing the current contents of files in your working tree. [S1]

For a compact file-level overview, use:

git show --stat --name-status abc1234

This summarizes changed paths and their status. Use git show abc1234 when you want to read the textual changes themselves. [S1] These commands display information; they do not modify the working tree.

Follow-up question

I see the file list, but I want to know what each file looked like before and after the commit. Is that the same as looking at the current version of those files?

Geez

No. The file list is a summary; the textual diff from git show <commit> lets you inspect the changes recorded in that commit. It is not necessarily the same as the files’ current contents. [S1]

For example, to inspect the recorded changes to notes.txt in commit abc1234, run git show abc1234 and look for that file’s section in the diff. The diff shows the changes, but it is not necessarily a complete copy of either version of the file.

If you instead want to see how your working tree differs from that commit, run git diff abc1234. That one-commit form compares the working tree with the specified commit. [S2] Choose git show for the commit’s recorded changes and git diff for the working-tree comparison.

Follow-up question

What if I want to compare the chosen commit with another commit, rather than with my current files? And what should I do if the output looks unusual?

Geez

Name both endpoints:

git diff abc1234 def5678

This compares the two specified commits. It does not list every commit between them; git diff compares the endpoints you supply. [S2]

For a single commit’s message and patch, use git show <commit>. One case to keep in mind is a merge commit: by default, git show displays it in a combined-diff format, whose interpretation may differ from an ordinary single-parent commit. [S1] If the output looks unfamiliar, check whether you are inspecting a merge commit before interpreting it as an ordinary commit diff.

Follow-up question

Can you give me a small workflow I can reuse and a way to record what I checked, without confusing the commit’s changes with the present state?

Geez

Use the commands that match your question; you do not need to run all of them:

git show [chosen-commit]
git show --stat --name-status [chosen-commit]
git diff [chosen-commit]
git diff [first-commit] [second-commit]

The first command shows the chosen commit’s message and textual diff; the second summarizes changed paths. The third compares the working tree with the chosen commit, and the fourth compares two commits. [S1] [S2]

To keep a note of your inspection, record something like: “Commit: [chosen-commit]. Comparison: [commit diff / working tree / two commits]. Files of interest: [paths].” That makes clear which view you checked without treating the commit’s recorded changes as a description of the current files.

A practical checklist

  • Choose the commit identifier you want to inspect.

  • Run git show <commit> for its message and textual diff.

  • Use git show --stat --name-status <commit> for a changed-path summary.

  • Use git diff <commit> for a working-tree comparison, or git diff <first-commit> <second-commit> to compare two commits.

  • For a merge commit, remember that git show uses a combined-diff format by default. [S1]

A few more useful answers

Does `git show <commit>` tell me what is in the working tree now?

It displays the specified commit’s message and recorded diff. Use git diff <commit> to compare that commit with the working tree. [S1] [S2]

Does `git diff <first-commit> <second-commit>` list all commits between them?

No. It compares the two specified commits; it does not list a commit range. [S2]

Why might a merge commit’s `git show` output look different?

By default, Git displays a merge commit using a combined-diff format, which may be interpreted differently from an ordinary single-parent commit. [S1]

Sources

References used for this guide.

  1. [S1] Git git-show documentation
    git-scm.com · Checked
  2. [S2] Git git-diff documentation
    git-scm.com · Checked

YOUR QUESTION. YOUR DETAILS.

Let’s work through your situation.

Get a tailored answer or help with your next task. Starts at $1, with a quote before you pay.

Ask your own question
← Back to Geez at Work