Git: List Files in Last Commit Only (No Diffs)
View only files changed in the last Git commit without diffs using git show --name-only or git diff --name-only HEAD~1 HEAD. Perfect for git show files, git diff files, git list files in scripts or quick audits—no patch details shown.
How can I view only the list of files that were changed in the last Git commit, without showing the actual changes?
To view only the list of files changed in the last Git commit without any diffs or patch details, run git show --name-only. This spits out just the file paths from HEAD, clean and simple. Or try git diff --name-only HEAD~1 HEAD for the same result—great when you need git show files or git diff files in a script.
Contents
- What Does git status Show for Changed Files?
- Primary Method: git show --name-only for File Lists
- Alternative: git diff --name-only for Precise Changes
- git log Variations and git status Tweaks
- Advanced Options Like Status Codes
- Scripting, Aliases, and git list files Tips
- Common Pitfalls with git show changes
- Sources
- Conclusion
What Does git status Show for Changed Files?
Ever committed something and wondered, “Wait, what files did I actually touch?” Git status is your first stop for the working tree, but it mixes staged, unstaged, and untracked files. For the last commit specifically—the ones baked into history—git status won’t cut it alone. It shows current workspace chaos, not past commits.
That said, if you’re mixing uncommitted work with history checks, git status --porcelain gives a machine-readable list of modified files right now. But for git status modified in the last commit? Nope. You’ll need targeted commands. Why bother? Quick audits, CI scripts, or just avoiding diff overload when reviewing git show commit files.
Here’s a quick table to compare basics:
| Command | What It Shows | Best For |
|---|---|---|
git status |
Working tree + index | Current changes (not committed) |
git show --name-only |
Last commit files only | git show files (primary) |
git diff --name-only HEAD~1 |
Files between commits | git diff files precision |
Simple, right? Let’s dive into the real heroes.
Primary Method: git show --name-only for File Lists
This is your go-to for git show files in the last commit. Type git show --name-only and boom—file paths only, no commit message, no diffs. It defaults to HEAD, so it’s instant for the most recent push.
$ git show --name-only
src/main.py
README.md
docs/changes.txt
See? Clean. Want to suppress the commit header entirely? Add --pretty="": git show --pretty="" --name-only. The official Git docs cover this porcelain command perfectly—porcelain means human-readable, unlike plumbing tools.
Pro tip: For a specific commit hash, swap HEAD: git show --name-only abc1234. Handles renames too (shows the new path). If your repo has submodules, -r recurses: git show --name-only -r.
Users on Stack Overflow swear by it—over 50 upvotes for this exact trick. Need git show last commit? Same command.
Alternative: git diff --name-only for Precise Changes
Sometimes git show feels too opinionated. Enter git diff --name-only HEAD~1 HEAD. This compares the previous commit to the last one, listing exactly what git diff files changed. Output mirrors git show—pure paths.
$ git diff --name-only HEAD~1 HEAD
src/utils.py
config.json
Why choose this over git show? Flexibility. Pinpoint any range: git diff --name-only main~1 main. The git diff documentation highlights --name-only as the no-patch flag, ideal for git diff name only or git changes list.
Compact? Add --stat for a summary, but stick to --name-only for lists. High-traffic threads like this Stack Overflow post recommend aliases for it.
But what if you want deletion status? --name-status tags them: A/added.txt M/modified.py D/deleted.log.
git log Variations and git status Tweaks
Git log isn’t just history—tailor it for files. git log -1 --name-only mimics git show files exactly. The -1 limits to the last commit.
$ git log -1 --name-only
commit abc1234...
src/app.js
Combine with --oneline for brevity, or --pretty=format: to nuke headers. Git log docs detail these for git log status or git log diff vibes.
For git status file vibes in history, git log --raw -1 shows abbreviated status (M for modified), but it’s chattier. Prefer name-only for purity. OpenSource.com contrasts raw vs. clean lists—raw adds modes, clean wins for speed.
Quick alias idea: git last-files = git log -1 --name-only. Covers git show commits too.
Advanced Options Like Status Codes
Power users, listen up. --name-status in git diff or show adds A/M/D/R codes: Added, Modified, Deleted, Renamed. Filter with --diff-filter=AMD: git show --name-status --diff-filter=AM.
$ git diff --name-status HEAD~1 HEAD
M src/main.py
D old/feature.txt
For git modified files only: --diff-filter=M. Blog posts like this demo it for audits.
Path filtering? git show --name-only '*.py' lists Python changes. UTF-8 paths? Git handles them natively now. Table of filters:
| Filter | Meaning | Example |
|---|---|---|
A |
Added | New files |
M |
Modified | Edited |
D |
Deleted | Removed |
R |
Renamed | Moved |
Perfect for git add modified files scripts.
Scripting, Aliases, and git list files Tips
Automate git list files? Use plumbing: git diff-tree --no-commit-id --name-only -r HEAD. Stable output for scripts—no porcelain changes.
alias glf='git diff-tree --no-commit-id --name-only -r'
glf # Lists last commit files
Stack Overflow praises diff-tree for reliability. Add to .gitconfig:
[alias]
files = !git diff-tree --no-commit-id --name-only -r HEAD
Bash loop? for commit in $(git log --oneline -3 | cut -d' ' -f1); do git show --name-only $commit; done. Covers git show changes in file across commits.
Common Pitfalls with git show changes
Merge commits? git show --name-only lists all touched files, not just yours—use git log -1 -m --name-only for parents. Empty commit? No files listed (expected).
Uncommitted changes confusing you? git diff --name-only (no args) shows workspace diffs, not history. Detached HEAD? Specify the commit.
Renames show as the new name—old vanishes. Sentry’s guide flags this. Windows paths? Use forward slashes.
Test in a fresh clone. Still stuck? git ls-files --modified for index vs. HEAD, but that’s not last-commit specific.
Sources
- How to see which files were changed in last commit — Stack Overflow answers on git show --name-only for recent commits: https://stackoverflow.com/questions/49853177/how-to-see-which-files-were-changed-in-last-commit
- git show Documentation — Official guide to git show --name-only and pretty format options: https://git-scm.com/docs/git-show
- How to list only the names of files that changed — Stack Overflow alias for git diff --name-only between commits: https://stackoverflow.com/questions/1552340/how-to-list-only-the-names-of-files-that-changed-between-two-commits
- git diff Documentation — Official details on git diff --name-only and status flags: https://git-scm.com/docs/git-diff
- How do I list all the files in a commit — Stack Overflow on diff-tree for scripting git list files: https://stackoverflow.com/questions/424071/how-do-i-list-all-the-files-in-a-commit
- git log Documentation — Official git log -1 --name-only for commit file lists: https://git-scm.com/docs/git-log
- git whatchanged and alternatives — OpenSource.com on git log --raw vs name-only: https://opensource.com/article/21/4/git-whatchanged
- Identify Modified Files in Git Commit — Blog tutorial on git show --name-status filtering: https://blog.openreplay.com/identify-modified-files-git-commit/
Conclusion
Stick with git show --name-only or git diff --name-only HEAD~1 HEAD for instant git show files or git diff files lists—no fuss. Aliases and filters level it up for daily workflows. You’ll save time reviewing git changes list forever. Fire up your terminal and try it now.