Inspect the changes in a Git commit

Read a commit’s patch, narrow it to selected paths, compare merge parents, or inspect a file’s full contents at that revision.

Best practices
Illustration of Git branches and version history

Run git show COMMIT to inspect an ordinary commit's metadata and patch. For a typical non-merge commit, the patch compares its snapshot with its parent. Merge commits need more care because they have multiple possible comparison bases.

Change the level of detail

Replace the sample ID with the commit you want to inspect:

git show a1b2c3d
git show --stat a1b2c3d
git show --name-only a1b2c3d
git show --word-diff a1b2c3d
git show a1b2c3d -- src/app.js

--stat summarizes affected files and line counts, while --name-only lists paths alongside the commit header. --word-diff highlights changes within lines, which is helpful for prose and small expression changes. Binary files and configured diff drivers may produce different representations from an ordinary text patch.

Compare snapshots directly

git diff a1b2c3d e4f5a6b
git diff 'a1b2c3d^!'

The first command compares two snapshots, including their net differences rather than every intermediate change. The ^! form selects a commit and its parents for diff processing; for an ordinary single-parent commit it shows that commit's change. For a merge it requests combined-diff behavior, so it is not universally equivalent to a first-parent patch. Quote revision expressions where shell expansion could interfere.

Inspect a merge against one parent

git show --no-patch --format='%P' a1b2c3d
git diff a1b2c3d^1 a1b2c3d

Verify which parent represents the intended mainline. Default combined merge output focuses on differences involving multiple parents and can omit files that appear in a first-parent comparison. An empty or short combined diff does not mean the merge had no net effect on the target branch.

git show --first-parent a1b2c3d is also useful for examining mainline-oriented merge changes, but the explicit two-snapshot diff makes the comparison boundary clear.

Find the commit or view a full file

Use git log --oneline to browse history. git log -S'keyword' searches for changes in the number of occurrences of a string; it does not find every edit on a line containing that string. git log -G'regex' searches matching added or removed lines. git reflog helps locate recent local ref movements.

To see the entire committed file rather than a patch:

git show a1b2c3d:src/app.js

If the file is absent in that snapshot, this command fails rather than retrieving a later version. Graphical commit-history tools, including IDE integrations, can provide equivalent views; confirm their selected revision and parent before relying on the displayed diff.

See git-show, git-diff, and git-log.

Get a tailored plan

Contact us

Join the community

Scan with WeChat
to join the community

Try Guance

Start online and pay only for what you use.

Get started

Choose a Guance plan

Code hosting