Is there a way to get the list of all new/deleted/modified directories/files in local/remote repository w.r.t each other in GIT ?
-
8`git status` seems to do that. – Blender Mar 28 '12 at 20:58
-
3This question is broad and not very clear -- with the result that the following answers cover quite different scenarios and use cases. Unfortunately, it's too late to make the question more specific as this would invalidate some of the (good) answers. – Anthony Geoghegan Jan 04 '19 at 17:09
-
Does this answer your question? [How to list only the names of files that changed between two commits](https://stackoverflow.com/questions/1552340/how-to-list-only-the-names-of-files-that-changed-between-two-commits) – cyreb7 Apr 07 '22 at 16:32
11 Answers
The best way to list these file is using git status --porcelain
.
For example:
git status --porcelain | awk 'match($1, "D"){print $2}'
shows you the tracked files which have been deleted from the local copy. You can delete all these files by appending an appropriate command to the pipe:
git status --porcelain | awk 'match($1, "D"){print $2}' | xargs git rm

- 118,144
- 57
- 340
- 684

- 624
- 5
- 2
I'm not sure what you mean by with respect to each other, but if you want an individual listing (e.g. all modified files) you can use git ls-files
with the right flags (for modified files it's -m
). If you want all of this info at once, you can use git status --porcelain
to get a script-parsable output of the status.

- 182,031
- 33
- 381
- 347
-
1Git status doesn't list the new directories/files that has been added to remote repo. Does it ? – Jean Mar 28 '12 at 21:32
-
@alertjean: What do you mean by "new"? Are they untracked? Are they added but not committed? What are they? – Lily Ballard Mar 28 '12 at 23:03
-
4Thanks, this is just what I was looking for. Now I can do e.g. `geany $(git ls-files -m)` – mwfearnley Apr 28 '16 at 09:27
To get just file names and status of the currently changed files you can simply:
git diff --name-status
You will get the bare output like this:
M a.txt
M b.txt
Now, pipe the output to cut
to extract the second column:
git diff --name-status | cut -f2
Then you'll have just the file names:
a.txt
b.txt

- 722
- 8
- 18
-
cut : The term 'cut' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:26 – amuliar Nov 12 '18 at 08:18
-
This example was created assuming you have a linux bash available. On windows, depending on your version, you'll need to install "Windows subsystem for Linux" on Windows 10 or something like Cygwin on previous windows versions. – LeandroN. Nov 12 '18 at 09:05
-
16
-
What is this magical `cut` command and why didn't I know about it sooner? Nice! – Paul Sturm Nov 04 '21 at 01:10
-
`git diff` does not list new files, just modified and deleted ones while `git status --porcelain` does. And for `cut`, maybe it was not the case at this time, but when installing Git you should have Git Bash installed with it, then no need to install "Windows subsystem for Linux", just run command on a Git Bash terminal. – gluttony Nov 03 '22 at 08:00
-
@PaulSturm check out "The Linux Command Line" by Shotts; you may have many more of those magical moments, most likely. – Life5ign Mar 22 '23 at 17:18
Use the dry-run (-n) option of git add
:
git add -A -n

- 18,973
- 19
- 95
- 159
-
1
-
exactly what I wanted too. simple and shows me what files are going to be pushed. – Chris Sharp Dec 04 '20 at 15:32
-
1
One way to do this is with the whatchanged
command:
$ git whatchanged
This shows which files changed for each commit in the tree and can be used to look at specifics as well. Take a look at git help whatchanged

- 1,888
- 11
- 22
-
2
-
I wanted to see list of files changed since beginning of project. This command helped a lot. Thanks! – mahen23 Jan 06 '22 at 06:17
What you probably want is something like:
git fetch # update what you know about the remote repo
git diff --name-status master origin/master
But it's pretty difficult to tell exactly what branches you want to diff from your question.

- 479,068
- 72
- 370
- 318
In my case I needed the list of all new/modified/untracked files. The below command did the trick:
git status --porcelain | cut -c 1-3 --complement
The cut -c 1-3 --complement
part is for removing the three initial status characters so that I could run arbitrary scripts with xargs
against the files. For instance, run eslint against all new/changed JavaScript files (in a nodejs repo):
git status --porcelain | cut -c 1-3 --complement | egrep .js$ | xargs npm run lint -- --fix

- 971
- 9
- 12
use with command --name-status
example with tags:
git diff v1.0.1 v1.0.2 --name-status
example with commits:
git diff b79810fc4d be69e41d1c --name-status
it will list all the updated files with their statuses:
M
- modified
D
- deleted
A
- added

- 827
- 8
- 16
git diff --name-only
does the work, but it shows the tracked files only. In order to include the new files, you may (temporary) add all files with git add .
and now the git diff --cached --name-only
should list all changed files. After that, you may git restore --staged .
to un-stage all files.

- 1,731
- 1
- 14
- 28
Do git diff
and you will see all the files changed and the details of what changed in those files

- 5,463
- 3
- 33
- 43
To git all files that your are added, modified deleted and new files you use two commands
git ls-files -o
to get all new files and git checkout
for get delete files , modified files and added files
git ls-files -o && git checkout
How I know deleted, modified , deleted files and new files if you see before the file
- A
this is added file to git
- D
this is deleted file
- M
this is Modified file
Nothing before the file this is a new file

- 1,987
- 1
- 23
- 34