# git diff --name-status for deleted files

4 messages from 2017-09-14 to 2017-09-15. Participants: Gene Thomas, Junio C Hamano.
Thread: https://gitlist.dev/t/46753

## Gene Thomas, 2017-09-14 22:11

Subject: git diff --name-status for deleted files
Message-ID: <PS1PR0601MB1883177814CA771567A7193B8A6F0@PS1PR0601MB1883.apcprd06.prod.outlook.com>
URL: https://gitlist.dev/e/PS1PR0601MB1883177814CA771567A7193B8A6F0%40PS1PR0601MB1883.apcprd06.prod.outlook.com

```
Hello,
          "git diff -name-status" is useful to list the files one has changed but it does not list file that one has deleted with "git rm". It would be really handy if it did. I am using git 2.9.3 on Ubuntu Linux 16.10.

Yours Sincerely,

Gene Thomas.

```

## Junio C Hamano, 2017-09-15 02:57

Subject: Re: git diff --name-status for deleted files
Message-ID: <xmqq1sn8zn1d.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqq1sn8zn1d.fsf%40gitster.mtv.corp.google.com
In-Reply-To: <PS1PR0601MB1883177814CA771567A7193B8A6F0@PS1PR0601MB1883.apcprd06.prod.outlook.com>

```
Gene Thomas <gene@nlc.co.nz> writes:

> Hello,
>           "git diff -name-status" is useful to list the files one
>           has changed but it does not list file that one has
>           deleted with "git rm". It would be really handy if it
>           did. I am using git 2.9.3 on Ubuntu Linux 16.10.

With or without --name-status option, "git diff" compares between
the contents you have in the index and in your working tree.  After
you modify contents of a file, i.e.

	edit file
	git add file

you would not see that file edited exactly because the file on the
filesystem is identical to what you added to the index with "git
add".

Your example works exactly the same way.  Instead of modifying the
contents of a file, removing the presense of the file and recording
that fact to the index (i.e. removing the path from the index, too)
is done with "git rm", so after running

	git rm file

your working tree would lack "file" and so would your index.  Hence
you wouldn't see "git diff" report any difference on "file".

Perhaps you wanted "git diff HEAD", which is a way to compare
between the contents you have in the tip commit and the paths in
your working tree thru the index?

```

## Gene Thomas, 2017-09-15 05:18

Subject: RE: git diff --name-status for deleted files
Message-ID: <PS1PR0601MB188364D92388A08D1D62E7078A6C0@PS1PR0601MB1883.apcprd06.prod.outlook.com>
URL: https://gitlist.dev/e/PS1PR0601MB188364D92388A08D1D62E7078A6C0%40PS1PR0601MB1883.apcprd06.prod.outlook.com
In-Reply-To: <xmqq1sn8zn1d.fsf@gitster.mtv.corp.google.com>

```
Junio,
           Thanks for your reply. So git is essentially doing a "git commit" when I "git rm". 

Gene.

-----Original Message-----
From: Junio C Hamano [mailto:gitster@pobox.com] 
Sent: Friday, 15 September 2017 2:58 PM
To: Gene Thomas <gene@nlc.co.nz>
Cc: git@vger.kernel.org
Subject: Re: git diff --name-status for deleted files

Gene Thomas <gene@nlc.co.nz> writes:

> Hello,
>           "git diff -name-status" is useful to list the files one
>           has changed but it does not list file that one has
>           deleted with "git rm". It would be really handy if it
>           did. I am using git 2.9.3 on Ubuntu Linux 16.10.

With or without --name-status option, "git diff" compares between the contents you have in the index and in your working tree.  After you modify contents of a file, i.e.

	edit file
	git add file

you would not see that file edited exactly because the file on the filesystem is identical to what you added to the index with "git add".

Your example works exactly the same way.  Instead of modifying the contents of a file, removing the presense of the file and recording that fact to the index (i.e. removing the path from the index, too) is done with "git rm", so after running

	git rm file

your working tree would lack "file" and so would your index.  Hence you wouldn't see "git diff" report any difference on "file".

Perhaps you wanted "git diff HEAD", which is a way to compare between the contents you have in the tip commit and the paths in your working tree thru the index?

```

## Junio C Hamano, 2017-09-15 05:47

Subject: Re: git diff --name-status for deleted files
Message-ID: <xmqqd16sy0ky.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqqd16sy0ky.fsf%40gitster.mtv.corp.google.com
In-Reply-To: <PS1PR0601MB188364D92388A08D1D62E7078A6C0@PS1PR0601MB1883.apcprd06.prod.outlook.com>

```
Gene Thomas <gene@nlc.co.nz> writes:

> Junio,
>            Thanks for your reply. So git is essentially doing a
>            "git commit" when I "git rm".

No. You'd probably need to read a bit more on Git; unlike other
systems like CVS and SVN, where you only have two states
(i.e. committed contents vs files on the filesystem), we have three
states (i.e. the index in addition to the above two).

"git add file" and "git rm file" make the index match what's on the
filesystem wrt "file".  They never touch committed contents, which
"git commit" command is about.


```
