git show changed - How to list all the files in a commit?





13 Answers

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>
before commits branch

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?




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.




I use changed alias a quite often. To set it up:

git config --global alias.changed 'show --pretty="format:" --name-only'

then:

git changed (lists files modified in last commit)   
git changed bAda55 (lists files modified in this commit)
git changed bAda55..ff0021 (lists files modified between those commits)

Similar commands that may be useful:

git log --name-status --oneline (very similar, but shows what actually happened M/C/D)
git show --name-only



$ git log 88ee8^..88ee8 --name-only --pretty="format:"



OK, there are couple of ways to show all files in a particular commit...

To reduce the info and show only names of the files which committed, you simply can add --name-only or --name-status flag..., these flags just show you the file names which are different from previous commits as you want...

So you can do git diff followed by --name-only, with two commit hashes after <sha0> <sha1>, something like below:

git diff --name-only 5f12f15 kag9f02 

I also create the below image to show all steps to go through in these situation:




I like to use

git show --stat <SHA1>^..<SHA2>



I like this:

git diff --name-status <SHA1> <SHA1>^



Use simple one line command, if you just want the list of files changed in the last commit:

git diff HEAD~1 --name-only



Display the log.

COMMIT can be blank ("") or the sha-1 or the sha-1 shortened.

git log COMMIT -1 --name-only

This will list just the files, very useful for further processing.

git log COMMIT -1 --name-only --pretty=format:"" | grep "[^\s]"



A combination of "git show --stat" (thanks Ryan) and a couple of sed commands should trim the data down for you:

git show --stat <SHA1> | sed -n "/ [\w]\*|/p" | sed "s/|.\*$//"

That will produce just the list of modified files.




git show HEAD@{0}

works fine for me




try this command for name and changes number of line

git show --stat <commit-hash>

only show file names

git show --stat --name-only  <commit-hash>

for get last commit hash then try this command

git log -1 or for all git log




Related


Tags

git   git-show