Jean
Jean

Reputation: 22725

GIT list of new/modified/deleted files

Is there a way to get the list of all new/deleted/modified directories/files in a local/remote repository with relation to each other in Git?

Upvotes: 73

Views: 96302

Answers (11)

Alex Sharapov
Alex Sharapov

Reputation: 654

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

Upvotes: 63

Serge Roussak
Serge Roussak

Reputation: 1807

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.

Upvotes: 3

Eng_Farghly
Eng_Farghly

Reputation: 3007

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

see this gif image get added, deleted, modified and new files in git

Upvotes: 1

Alfeu
Alfeu

Reputation: 991

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

Upvotes: 8

Sandeep Amarnath
Sandeep Amarnath

Reputation: 6916

Do git diff and you will see all the files changed and the details of what changed in those files

Upvotes: 0

LeandroN.
LeandroN.

Reputation: 792

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

Upvotes: 29

Oleksa O.
Oleksa O.

Reputation: 905

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

Upvotes: 2

Trident D'Gao
Trident D'Gao

Reputation: 19740

Use the dry-run (-n) option of git add:

git add -A -n

Upvotes: 21

sparrow
sparrow

Reputation: 1957

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

Upvotes: 20

Cascabel
Cascabel

Reputation: 497202

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.

Upvotes: 13

Lily Ballard
Lily Ballard

Reputation: 185721

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.

Upvotes: 41

Related Questions