[git] 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?

This question is related to git git-show

The answer is


I thought I would share a summary of my alias.. also I find using 'zsh' great with git it chroma keys everything nicely and tells you want branch are in all of the time by changing the command prompt.

For those covering from SVN you will find this useful: (this is a combination of ideas from different threads, I only take credit of knowing how to use copy/paste)

.gitconfig:
        ls = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)%an%Creset' --abbrev-commit --date=relative --name-status

>>git ls
* 99f21a6 - (HEAD -> swift) New Files from xcode 7 (11 hours ago) Jim Zucker| 
| A     icds.xcodeproj/project.pbxproj
| A     icds.xcodeproj/project.xcworkspace/contents.xcworkspacedata
| A     icds/AppDelegate.m
| A     icds/Assets.xcassets/AppIcon.appiconset/Contents.json

* e0a1bb6 - Move everything to old (11 hours ago) Jim Zucker| 
| D     Classes/AppInfoViewControler.h
| D     Classes/AppInfoViewControler.m
| D     Classes/CurveInstrument.h


.gitconfig: 
       lt = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)%an%Creset' --abbrev-commit --date=relative

>>git lt
* 99f21a6 - (HEAD -> swift) New Files from xcode 7 (11 hours ago) Jim Zucker
* e0a1bb6 - Move everything to old (11 hours ago) Jim Zucker
* 778bda6 - Cleanup for new project (11 hours ago) Jim Zucker
* 7373b5e - clean up files from old version (11 hours ago) Jim Zucker
* 14a8d53 - (tag: 1.x, origin/swift, origin/master, master) Initial Commit (16 hours ago) Jim Zucker


.gitconfig
lt = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)%an%Creset' --abbrev-commit --date=relative

>> git lt

commit 99f21a61de832bad7b2bdb74066a08cac3d0bf3c
Author: Jim Zucker <[email protected]>
Date:   Tue Dec 1 22:23:10 2015 -0800

    New Files from xcode 7

A       icds.xcodeproj/project.pbxproj
A       icds.xcodeproj/project.xcworkspace/contents.xcworkspacedata


commit e0a1bb6b59ed6a4f9147e894d7f7fe00283fce8d
Author: Jim Zucker <[email protected]>
Date:   Tue Dec 1 22:17:00 2015 -0800

    Move everything to old

D       Classes/AppInfoViewControler.h
D       Classes/AppInfoViewControler.m
D       Classes/CurveInstrument.h
D       Classes/CurveInstrument.m

I use this to get list of changed files in merge commit

? git log -m -1 --name-only --pretty="format:"
configs/anotherconfig.xml
configs/configsInRepo.xml

or

? git log -m -1 --name-status --pretty="format:"
A       configs/anotherconfig.xml
M       configs/configsInRepo.xml

There's also git whatchanged, which is more low level than git log

NAME
       git-whatchanged - Show logs with difference each commit introduces

It outputs the commit summary with a list of files beneath it with their modes and if there added(A), deleted(D) or modified(M);

$ git whatchanged f31a441398fb7834fde24c5b0c2974182a431363

Would give something like:

commit f31a441398fb7834fde24c5b0c2974182a431363
Author: xx <[email protected]>
Date:   Tue Sep 29 17:23:22 2015 +0200

    added fb skd and XLForm

:000000 100644 0000000... 90a20d7... A  Pods/Bolts/Bolts/Common/BFCancellationToken.h
:000000 100644 0000000... b5006d0... A  Pods/Bolts/Bolts/Common/BFCancellationToken.m
:000000 100644 0000000... 3e7b711... A  Pods/Bolts/Bolts/Common/BFCancellationTokenRegistration.h
:000000 100644 0000000... 9c8a7ae... A  Pods/Bolts/Bolts/Common/BFCancellationTokenRegistration.m
:000000 100644 0000000... bd6e7a1... A  Pods/Bolts/Bolts/Common/BFCancellationTokenSource.h
:000000 100644 0000000... 947f725... A  Pods/Bolts/Bolts/Common/BFCancellationTokenSource.m
:000000 100644 0000000... cf7dcdf... A  Pods/Bolts/Bolts/Common/BFDefines.h
:000000 100644 0000000... 02af9ba... A  Pods/Bolts/Bolts/Common/BFExecutor.h
:000000 100644 0000000... 292e27c... A  Pods/Bolts/Bolts/Common/BFExecutor.m
:000000 100644 0000000... 827071d... A  Pods/Bolts/Bolts/Common/BFTask.h
...

I know this answer doesn't really match "with no extraneous information.", but I still think this list is more useful then just the filenames.


List all files in a commit tree:

git ls-tree --name-only --full-tree a21e610

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>

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

git diff HEAD~1 --name-only

Simplest form:

git show --stat (hash)

That's easier to remember and it will give you all the information you need.

If you really want only the names of the files you could add the --name-only option.

git show --stat --name-only (hash)


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>.


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]"

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

git diff HEAD~1 --name-only

I like this:

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

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:

git diff --name-only 5f12f15 kag9f02


I like to use

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

There is a simple trick to view as a file listing, just add : after the hash.

git show 9d3a52c474:

You can then drill in,

git show 9d3a52c474:someDir/someOtherDir

If you hit a file you'll get the raw version of the file; which sometimes is what you want if you're only looking for a nice reference or key pieces of code (diffs can make everything a mess),

git show 9d3a52c474:someDir/someOtherDir/somefile

Only drawback of this method is that it doesn't easily show a tree of files.


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

Found a perfect answer to this:

git show --name-status --oneline <commit-hash>

So that I can know

which files were just modified M

Which files were newly added , A

Which files were deleted , D

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.


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

Using --name-status will also include the change (added, modified, deleted etc) next to each file

git diff --name-status START_COMMIT..END_COMMIT

List the files that changed in a commit:

git diff --name-only SHA1^ SHA1

This doesn't show log messages, extra newlines, or any other clutter. This works for any commit, not just the current one. Not sure why it hasn't quite been mentioned yet, so I'm adding it.


Only the file list (not even commit message):

git show --name-only --pretty=format:

E.g. open all changed files in your editor:

git show --name-only --pretty=format: | xargs "$EDITOR"

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.


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.


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 thought I would share a summary of my alias.. also I find using 'zsh' great with git it chroma keys everything nicely and tells you want branch are in all of the time by changing the command prompt.

For those covering from SVN you will find this useful: (this is a combination of ideas from different threads, I only take credit of knowing how to use copy/paste)

.gitconfig:
        ls = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)%an%Creset' --abbrev-commit --date=relative --name-status

>>git ls
* 99f21a6 - (HEAD -> swift) New Files from xcode 7 (11 hours ago) Jim Zucker| 
| A     icds.xcodeproj/project.pbxproj
| A     icds.xcodeproj/project.xcworkspace/contents.xcworkspacedata
| A     icds/AppDelegate.m
| A     icds/Assets.xcassets/AppIcon.appiconset/Contents.json

* e0a1bb6 - Move everything to old (11 hours ago) Jim Zucker| 
| D     Classes/AppInfoViewControler.h
| D     Classes/AppInfoViewControler.m
| D     Classes/CurveInstrument.h


.gitconfig: 
       lt = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)%an%Creset' --abbrev-commit --date=relative

>>git lt
* 99f21a6 - (HEAD -> swift) New Files from xcode 7 (11 hours ago) Jim Zucker
* e0a1bb6 - Move everything to old (11 hours ago) Jim Zucker
* 778bda6 - Cleanup for new project (11 hours ago) Jim Zucker
* 7373b5e - clean up files from old version (11 hours ago) Jim Zucker
* 14a8d53 - (tag: 1.x, origin/swift, origin/master, master) Initial Commit (16 hours ago) Jim Zucker


.gitconfig
lt = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)%an%Creset' --abbrev-commit --date=relative

>> git lt

commit 99f21a61de832bad7b2bdb74066a08cac3d0bf3c
Author: Jim Zucker <[email protected]>
Date:   Tue Dec 1 22:23:10 2015 -0800

    New Files from xcode 7

A       icds.xcodeproj/project.pbxproj
A       icds.xcodeproj/project.xcworkspace/contents.xcworkspacedata


commit e0a1bb6b59ed6a4f9147e894d7f7fe00283fce8d
Author: Jim Zucker <[email protected]>
Date:   Tue Dec 1 22:17:00 2015 -0800

    Move everything to old

D       Classes/AppInfoViewControler.h
D       Classes/AppInfoViewControler.m
D       Classes/CurveInstrument.h
D       Classes/CurveInstrument.m

Use

git log --name-status

This will show you the commit id, message, the files changed and whether it was modified, created, added or deleted. Somewhat of a all-in-one command.


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

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.


I'll just assume that gitk is not desired for this. In that case, try git show --name-only <sha>.


List all files in a commit tree:

git ls-tree --name-only --full-tree a21e610

I use this to get list of modified files between two changesets:

git diff --name-status <SHA1> <SHA2> | cut -f2

git show HEAD@{0}

works fine for me


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:

git diff --name-only 5f12f15 kag9f02


Using standard git diff command (also good for scripting):

git diff --name-only <sha>^ <sha>

If you want also the status of the changed files:

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

This works well with merge commits.


Simplest form:

git show --stat (hash)

That's easier to remember and it will give you all the information you need.

If you really want only the names of the files you could add the --name-only option.

git show --stat --name-only (hash)


If you are using oh-my-zsh and git plugin, the glg shortcut is helpful.


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]"

List the files that changed in a commit:

git diff --name-only SHA1^ SHA1

This doesn't show log messages, extra newlines, or any other clutter. This works for any commit, not just the current one. Not sure why it hasn't quite been mentioned yet, so I'm adding it.


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.


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>

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

last commit with show files name and file status modify,create or delete

 git log -1 --oneline --name-status <commit-hash>

or for all

git log

for more advanced git log information read this article

https://devhints.io/git-log-format

https://devhints.io/git-log


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

I use this to get list of modified files between two changesets:

git diff --name-status <SHA1> <SHA2> | cut -f2

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.


I use this to get list of changed files in merge commit

? git log -m -1 --name-only --pretty="format:"
configs/anotherconfig.xml
configs/configsInRepo.xml

or

? git log -m -1 --name-status --pretty="format:"
A       configs/anotherconfig.xml
M       configs/configsInRepo.xml

This should work:

git status

This will show what is not staged and what is staged.


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

I like to use

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

I like this:

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

Only the file list (not even commit message):

git show --name-only --pretty=format:

E.g. open all changed files in your editor:

git show --name-only --pretty=format: | xargs "$EDITOR"

This should work:

git status

This will show what is not staged and what is staged.


I'll just assume that gitk is not desired for this. In that case, try git show --name-only <sha>.


Use

git log --name-status

This will show you the commit id, message, the files changed and whether it was modified, created, added or deleted. Somewhat of a all-in-one command.


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

last commit with show files name and file status modify,create or delete

 git log -1 --oneline --name-status <commit-hash>

or for all

git log

for more advanced git log information read this article

https://devhints.io/git-log-format

https://devhints.io/git-log


There's also git whatchanged, which is more low level than git log

NAME
       git-whatchanged - Show logs with difference each commit introduces

It outputs the commit summary with a list of files beneath it with their modes and if there added(A), deleted(D) or modified(M);

$ git whatchanged f31a441398fb7834fde24c5b0c2974182a431363

Would give something like:

commit f31a441398fb7834fde24c5b0c2974182a431363
Author: xx <[email protected]>
Date:   Tue Sep 29 17:23:22 2015 +0200

    added fb skd and XLForm

:000000 100644 0000000... 90a20d7... A  Pods/Bolts/Bolts/Common/BFCancellationToken.h
:000000 100644 0000000... b5006d0... A  Pods/Bolts/Bolts/Common/BFCancellationToken.m
:000000 100644 0000000... 3e7b711... A  Pods/Bolts/Bolts/Common/BFCancellationTokenRegistration.h
:000000 100644 0000000... 9c8a7ae... A  Pods/Bolts/Bolts/Common/BFCancellationTokenRegistration.m
:000000 100644 0000000... bd6e7a1... A  Pods/Bolts/Bolts/Common/BFCancellationTokenSource.h
:000000 100644 0000000... 947f725... A  Pods/Bolts/Bolts/Common/BFCancellationTokenSource.m
:000000 100644 0000000... cf7dcdf... A  Pods/Bolts/Bolts/Common/BFDefines.h
:000000 100644 0000000... 02af9ba... A  Pods/Bolts/Bolts/Common/BFExecutor.h
:000000 100644 0000000... 292e27c... A  Pods/Bolts/Bolts/Common/BFExecutor.m
:000000 100644 0000000... 827071d... A  Pods/Bolts/Bolts/Common/BFTask.h
...

I know this answer doesn't really match "with no extraneous information.", but I still think this list is more useful then just the filenames.


If you are using oh-my-zsh and git plugin, the glg shortcut is helpful.


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

I'll just assume that gitk is not desired for this. In that case, try git show --name-only <sha>.


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

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

Found a perfect answer to this:

git show --name-status --oneline <commit-hash>

So that I can know

which files were just modified M

Which files were newly added , A

Which files were deleted , D

There is a simple trick to view as a file listing, just add : after the hash.

git show 9d3a52c474:

You can then drill in,

git show 9d3a52c474:someDir/someOtherDir

If you hit a file you'll get the raw version of the file; which sometimes is what you want if you're only looking for a nice reference or key pieces of code (diffs can make everything a mess),

git show 9d3a52c474:someDir/someOtherDir/somefile

Only drawback of this method is that it doesn't easily show a tree of files.


Using standard git diff command (also good for scripting):

git diff --name-only <sha>^ <sha>

If you want also the status of the changed files:

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

This works well with merge commits.