3603

How can I print a plain list of all files that were part of a given commit?

Although the following lists the files, it also includes unwanted diff information for each:

git show a303aa90779efdd2f6b9d90693e2cbbbe4613c1d
4
  • 59
    I came here looking for something a bit different. I want to see all files modified for a set of commits and wound up using git log --until 2013-05-21 --pretty="short" --name-only with a good effect. Commented Dec 12, 2013 at 17:40
  • 8
    Use this command to get all changes from previous n commits till master: git diff-tree --name-status -r @{3} master
    – ako
    Commented Jun 22, 2018 at 13:57
  • 6
    git diff --name-only master - To list ALL changed files on current branch, comparing to master branch.
    – Noam Manos
    Commented Jun 30, 2019 at 9:39
  • 1
    You can check this answer out: stackoverflow.com/questions/17563726/… Commented Mar 9, 2022 at 20:36

30 Answers 30

4832

Preferred Way (because it's a plumbing command; meant to be programmatic):

$ git diff-tree --no-commit-id --name-only bd61ad98 -r
index.html
javascript/application.js
javascript/ie6.js

Another Way (less preferred for scripts, because it's a porcelain command; meant to be user-facing)

$ git show --pretty="" --name-only bd61ad98    
index.html
javascript/application.js
javascript/ie6.js

  • The --no-commit-id suppresses the commit ID output.
  • The --pretty argument specifies an empty format string to avoid the cruft at the beginning.
  • The --name-only argument shows only the file names that were affected (Thanks Hank). Use --name-status instead, if you want to see what happened to each file (Deleted, Modified, Added)
  • The -r argument is to recurse into sub-trees
32
  • 52
    It should be noted that diff-tree won't work when looking at the root commit.
    – jbranchaud
    Commented Mar 6, 2013 at 5:52
  • 388
    Replacing the --name-only option with --name-status will give more clear summary.
    – Kurt Zhong
    Commented Apr 11, 2013 at 3:58
  • 39
    If you want it to work on the root commit, use the --root flag. From the man page: "When --root is specified the initial commit will be shown as a big creation event. This is equivalent to a diff against the NULL tree."
    – Chris
    Commented Sep 23, 2013 at 18:26
  • 32
    git log --name-only -n 1 <hash> The last commit would be: git log --name-only -n 1 HEAD~1..HEAD
    – Kurt
    Commented Nov 11, 2013 at 4:20
  • 25
    If anyone is wondering (like I was) why the first way is "preferred," it goes back to @drizzt 's comment; git show is "porcelain" (meant to be user facing) and git diff-tree is "plumbing" (meant to be used programmatically, e.g. from scripts). The interface for the former may change over time (so the git maintainers could drop --name-only although I don't imagine they would) for useability reasons, whereas the interface for the latter will be kept as stable as possible for compatibility reasons.
    – killscreen
    Commented Jun 29, 2015 at 4:42
358

If you want to get the list of changed files:

git diff-tree --no-commit-id --name-only -r <commit-ish>

If you want to get the list of all files in a commit, you can use

git ls-tree --name-only -r <commit-ish>
15
  • 1
    The ls-tree with --name-only does not seem to work on 1.6.4.4 or 1.6.3.3. Do you think this is a bug ?
    – krosenvold
    Commented Oct 10, 2009 at 10:20
  • 2
    It turns out the ordering of the parameters is significant here. The one in your post does not work, while the one in your response does work - at least until you update your post ;)
    – krosenvold
    Commented Oct 10, 2009 at 15:17
  • 5
    Pass --no-commit-id to avoid printing the SHA1, like so: git diff-tree --no-commit-id --name-only -r <commit-ish> Commented Aug 15, 2012 at 20:00
  • 1
    diff-tree doesn't return anything, possibly because the commit I refer to added files, but not changed any existing. ls-tree gives me a list of all files in the repo, not just the files added/altered in the last commit. I wonder if there's a 3rd command to just list all new files (i.e. added in that given commit)?
    – CodeManX
    Commented Nov 17, 2015 at 23:03
  • 4
    @CoDEmanX : You didn't miss adding -r / -t option, did you? Because diff-tree handles both modified and added files. If you want to list all new (added) files, use git diff-tree -r --name-only --no-commit-id --diff-filter=A <commit-ish> Commented Nov 17, 2015 at 23:15
318

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

2
  • 44
    --name-only is plenty in most cases where i needed it; Therefore, upvoted the shortest solution (and the only one that i'd remember in 1 try).
    – Erik S
    Commented Aug 1, 2012 at 21:42
  • 1
    As someone who really likes CLI git, gitk is actually a decent way of reviewing the files and displaying the file that the diff is on. e.g. Code reviewing a monster commit from a peer. Commented Oct 27, 2017 at 21:56
277

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
5
  • 2
    Very nice. To define an alias: alias gits='git show --stat --oneline', then gits by itself shows the latest changes (in HEAD), while gits b24f5fb can be used to show any revision's changes. Commented Dec 5, 2013 at 3:03
  • 5
    One could also create a git alias... e.g. perhaps git config --global alias.changes 'show --stat --oneline'. Then you can type git changes (with an optional commit-ish) and get the output from the first examples above.
    – lindes
    Commented Dec 5, 2013 at 17:31
  • Git for Windows requires double quotes: git config --global alias.changes "show --stat --oneline" Commented Jul 25, 2017 at 2:46
  • 3
    Nice. And unlike the accepted answer, git show also works for reviewing stashed changes: e.g. git show --stat --oneline stash@{1}
    – Jeff Ward
    Commented Jul 26, 2017 at 19:00
  • 1
    this is what I've really needed ! unlike " git diff-tree --name-status -r <commit_id>", with this command I may see affected files in the merge too ! thanks !
    – dobrivoje
    Commented Feb 19, 2019 at 11:02
135

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.

3
  • 3
    Thanks, it helps. BTW: use git show 5944ad2a8b5 --name-only to list the name of a specific commit Commented Aug 8, 2019 at 6:37
  • What is the difference compared to leaving --name-only out? Or in other words, what is it supposed to do and how does it answer the question? Commented Apr 9, 2021 at 21:15
  • --name-only adds the filenames of the files that are included in the commit
    – dstudeba
    Commented Apr 10 at 21:57
78

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

Or as Ethan points out:

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
3
  • 5
    If you use git diff --name-status START_COMMIT..END_COMMIT then you don't need the trailing |sort | uniq.
    – Ethan
    Commented Sep 17, 2013 at 20:12
  • 1
    Correction to above comment: git diff --name-only START_COMMIT..END_COMMIT
    – Ethan
    Commented Sep 17, 2013 at 20:19
  • This is what I was looking for. How I used it: git diff --name-only START_COMMIT..END_COMMIT | grep -v -e '**.png' -e '**.xml'. I wanted a list of code changes only for a huge PR that had added thousands of PNGs and XML layouts. Commented Sep 18, 2017 at 16:39
73

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)

1
  • 2
    --name-only will still include a couple of header lines containing information such as the author, date and the commit message. Commented Sep 29, 2016 at 15:14
54

I use the changed alias 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
1
  • It is there anything special about "changed"? Is it an arbitrary choice of a word? A convention? Something built-in? Commented Apr 9, 2021 at 21:12
53

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 an all-in-one command.

1
  • this brings up a huge list of every recent commit, I have to hold down the ENTER button to see everything, then it locks my cmd. no thanks.
    – john k
    Commented Nov 22, 2021 at 15:24
48

Try this command for name and changes number of lines

git show --stat <commit-hash>

Only show file names

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

For getting the last commit hash, 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 these articles:

2
  • 2
    @DanFare "fatal: unrecognized argument: --names-only" from 2.20.1.windows.1 Commented Mar 1, 2019 at 18:24
  • "for all"... just git log doesn't give you the filenames... Commented Mar 25, 2022 at 19:42
46

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

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

If you also want the status of the changed files:

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

This works well with merge commits.

0
38

To list the files changed on a particular commit:

git show --pretty=%gd --stat <commit_id>

To list the files changed on recent commit:

git show --pretty=%gd --stat
28
$ git log 88ee8^..88ee8 --name-only --pretty="format:"
1
  • 1
    An explanation would be in order. Commented Apr 9, 2021 at 20:57
23
git show --name-only a303aa90779efdd2f6b9d90693e2cbbbe4613c1d
0
22

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

To reduce the information 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 created the below image to show all steps to go through in these situations:

git diff --name-only 5f12f15 kag9f02

0
20

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

git diff HEAD~1 --name-only
0
17

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 they were 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 than just the filenames.

1
  • Plus, just one command whatchanged instead of supplying parameters.
    – Gabrielius
    Commented Jan 25, 2016 at 12:19
17

I use this to get the list of changed files in a 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
16

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

git diff --name-status <SHA1> <SHA2> | cut -f2
1
  • Yeah but the status can be quite handy at well (for isntance, you might want to grep to display all files except those that have been deleted with something like git diff --name-status .. | grep ^[^D] | cut -f2 Commented Sep 17, 2014 at 9:19
15

I like to use

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

I 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)

13

I like this:

git diff --name-status <SHA1> <SHA1>^
1
  • I think this gets the A & D (add and delete) file statuses backwards, because it's showing the diff from the specified commit to the previous commit, instead of the other way around. It should be git diff --name-status <SHA1>^ <SHA1>.
    – Troy Gizzi
    Commented Jan 3, 2015 at 5:14
10

Display the log.

COMMIT can be blank (""), the SHA-1 hash, or a shortened version of the SHA-1 hash.

git log COMMIT -1 --name-only

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

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

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.

2
  • This two looks the same: git diff SHA1^ SHA1 and git show SHA1. Commented Jun 27, 2016 at 15:16
  • 1
    @mrW Those commands produce similar output, but git show also shows the commit message
    – Newtonx
    Commented Jun 27, 2016 at 23:01
10

Perhaps I missed it did anyone mention if you want to augment the log x previous commits using the 'log' command to include the names of the files effected then add --name-only on the end.

so:

git log -n3

to see the last comments of the last 3 commits.

git log -n3 --name-only

to see the comments and files effected in the last 3 commits.

0
9

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"
2
  • This works perfectly however it only shows the last commit. If you want to target a specific commit see answer by @Ryan McGeary
    – Hamfri
    Commented Jun 18, 2020 at 10:05
  • @Hamfri: No, it doesn't only work for the last commit. It's just the default of git show. Commented Sep 15, 2020 at 14:26
6

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

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

1
  • It will not only find files changed in a commit, but all files that are in the tree of that commit. Great if you want that, but not so great if you want to see which files changed.
    – mihi
    Commented Oct 13, 2021 at 20:57
6

A combination of git show --stat 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.

0
4

If your commit happens to be at the initial HEAD position

git show HEAD@{0}

this should work fine.

1
  • All: An explanation would be in order. Why and how does it work? Commented Apr 9, 2021 at 21:06
3

List all files in a commit tree:

git ls-tree --name-only --full-tree a21e610
2
  • It shows only top-level list of files / directories for me. Commented Jul 18 at 7:59
  • @MartinFlaska To list all, add --recursive Commented Jul 18 at 8:41

Not the answer you're looking for? Browse other questions tagged or ask your own question.