39

How do I list all the files that I committed to a specific branch? I've committed about 40+ files to a branch, and I need to find the file names because I am trying to debug something, hard to do when I don't remember the file names.

git log only gives me a long list of commits but not the actual files.

Guy Avraham
  • 3,482
  • 3
  • 38
  • 50
iCodeLikeImDrunk
  • 17,085
  • 35
  • 108
  • 169

9 Answers9

42

Have you tried git ls-tree?

git ls-tree --name-only -r <branch_name> 

--name-only gives you just the file names. -r recurses into sub directories.

If you want the name of the sub-directory listed before recursing into it, add -t to the argument list.

Carl
  • 43,122
  • 10
  • 80
  • 104
  • 1
    Wonderful answer. The question you answered is not immediately obvious, and I do know about git log. – octopusgrabbus Apr 07 '15 at 18:36
  • 4
    i got list of tons of files instead of just few from my branch. `git log --name-only` looks like the appropriate answer to see files modified by commits in the branch – Eugene Jul 04 '17 at 16:46
  • @Eugene: A down vote is a bit harsh, don't you think? – Carl Jul 05 '17 at 20:01
  • 1
    @Carl because ? i think that answer is wrong and offered solution doesn't work i should up vote it ? i have up voted the answer below. this is the purpose of these 2 arrows - to outline the best solution which is appropriate for the most of users. – Eugene Jul 06 '17 at 06:42
  • Perfect! Thanks! Exactly what I was looking for. – 5lb Bass Oct 09 '18 at 19:55
  • 2
    `git ls-tree --name-only $branch $directory/` for a list of a specific directory – Hashbrown Sep 12 '19 at 10:19
23

git log --name-only worked for me.

Jay Bienvenu
  • 3,069
  • 5
  • 33
  • 44
21

If your branch was derived from master you can use this command to list all new files that where added after branching:

git diff master...new-branch --name-status --diff-filter=A

Available filter for --diff-filter are:

Added (A), Copied (C), Deleted (D), Modified (M), Renamed (R)
KL-7
  • 46,000
  • 9
  • 87
  • 74
  • I you expect to get some help, you should provide more information. Do you get wrong output? Do you get an error? – KL-7 Aug 17 '12 at 13:00
  • 1
    This worked for me. I created a branch, made some commits and was looking for only the modified files. The ls-tree solution gave me all the files in my initial checkout - dunno why - but this gave me only the modified files in the new branch. Thanks a lot!! – corl Sep 06 '14 at 04:25
12

The git ls-files command lists all the files that exist in the latest commit on the current branch.

Or, you can use git diff --name-only to show a list of the files that are different between any two arbitrary commits.

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
8

git log --name-status will give the names and status of changed files in each commit

dorsh
  • 23,750
  • 2
  • 27
  • 29
2

git log --name-only Worked for me.

Newton Singh
  • 332
  • 3
  • 9
0

This one can be useful, if you want to know all distinct files that got modified since branching:

git log --name-status develop...branchname | grep -E "^[AMD]\s" | sort -u

And this variant will list the subset of them that you modified:

git log --name-status develop...branchname --author= | grep -E "^[AMD]\s" | sort -u

Fabien Haddadi
  • 1,814
  • 17
  • 22
-1

try using smartgit. it is gui client for git. it has very useful UI and is free for non-commercial use.

tputnoky
  • 155
  • 1
  • 1
  • 8
  • 1
    This didn't answer his question directly, but the information is useful. Thanks. – octopusgrabbus Apr 07 '15 at 18:41
  • Soooo, how do you use smartgit to see what files have been committed? That would actually answer the question. – SMBiggs Sep 03 '15 at 15:31
  • @Scott Biggs, see log with `ctrl+L` for repository, folder or file. In logs windows *select two commits* to see diff between them with list of files, and compare pane. – kyb Apr 16 '18 at 17:37
-2
git diff development...crmq-2405 --name-status --diff-filter=A

will list all files that have been added to the new branch that are not in the mail - in this case development main branch.

git diff development...crmq-2405 --name-status

This variant will show all files in the new branch

Generic form:

git diff main_branch...new_branch --name-status

and yes, order does matter.

rkta
  • 3,959
  • 7
  • 25
  • 37
Jim
  • 1
  • I think this is being downvoted because the parameters are in fact backward. I got zero results for `development…base`, but `git diff base..development --name-status --diff-filter=A` did list off the four new files in my dev branch. – cbowns Mar 13 '20 at 23:27