How to list all the files in a commit?
I am looking for a simple
git command that provides a nicely formatted list of all files that were part of the commit given by a hash (SHA1), with no extraneous information.
I have tried:
git show a303aa90779efdd2f6b9d90693e2cbbbe4613c1d
Although it lists the files, it also includes unwanted diff information for each.
Is there another
git command that will provide just the list I want, so that I can avoid parsing it from the
git show output?
Preferred Way (because it's a plumbing command; meant to be programmatic):
Another Way (less preferred for scripts, because it's a porcelain command; meant to be user-facing)
--no-commit-idsuppresses the commit ID output.
--prettyargument specifies an empty format string to avoid the cruft at the beginning.
--name-onlyargument shows only the file names that were affected (Thanks Hank). Use
--name-statusinstead, if you want to see what happened to each file (Deleted, Modified, Added)
-rargument is to recurse into sub-trees
Read more... Read less...
If you want to get list of changed files:
git diff-tree --no-commit-id --name-only -r <commit-ish>
If you want to get list of all files in a commit, you can use
git ls-tree --name-only -r <commit-ish>
I'll just assume that
gitk is not desired for this. In that case, try
git show --name-only <sha>.
I personally use the combination of --stat and --oneline with the show command:
git show --stat --oneline HEAD git show --stat --oneline b24f5fb git show --stat --oneline HEAD^^..HEAD
If you do not like/want the addition/removal stats, you can replace --stat with --name-only
git show --name-only --oneline HEAD git show --name-only --oneline b24f5fb git show --name-only --oneline HEAD^^..HEAD
You can also do
git log --name-only
and you can browse through various commits, commit messages and the changed files.
Type q to get your prompt back.
Recently I needed to list all changed files between two commits. So I used this (also *nix specific) command
git show --pretty="format:" --name-only START_COMMIT..END_COMMIT | sort | uniq
Update: Or as Ethan points out below
git diff --name-only START_COMMIT..END_COMMIT
--name-status will also include the change (added, modified, deleted etc) next to each file
git diff --name-status START_COMMIT..END_COMMIT