# How do I get the correct modification status after running git diff?

4 messages from 2010-03-04 to 2010-03-04. Participants: jateeq, Michael J Gruber, Andreas Schwab.
Thread: https://gitlist.dev/t/22909

## jateeq, 2010-03-04 15:40

Subject: How do I get the correct modification status after running git diff?
Message-ID: <27782430.post@talk.nabble.com>
URL: https://gitlist.dev/e/27782430.post%40talk.nabble.com

```

Hello,

I have added a new file to a working repository, and would like to run a
diff between the last commit and whatever is int he working tree, along with
an identification of what kind of a modification it was. Currently, I am
adding all files to the index with the -N option, and then running a git
diff --name-status. This works well for existing files that have been
modified or deleted, but fails if a file is rename or is added. Does anyone
know of the right way to do this? The commands I am using to add and diff
newly added files are as follows in the sequence shown.

Commands:
echo "this is a new file" > file1.xml
git add -N .
git diff --name-status

The output is :
M   file1.xml

I want the status to show A for the newly added file (and R for renamed
files but I don't know if that's possible).

Thank You,
Jawad.
-- 
View this message in context: http://old.nabble.com/How-do-I-get-the-correct-modification-status-after-running-git-diff--tp27782430p27782430.html
Sent from the git mailing list archive at Nabble.com.

```

## jateeq, 2010-03-04 16:11

Subject: Re: How do I get the correct modification status after running git diff?
Message-ID: <27782895.post@talk.nabble.com>
URL: https://gitlist.dev/e/27782895.post%40talk.nabble.com
In-Reply-To: <27782430.post@talk.nabble.com>

```

Ok, so I think I know what I was doing wrong... i wasn't comparing the
working tree with the last commit (HEAD), although I still don't know what
exactly I was comparing the working tree with. On reading the manual a
little more carefully, I realised the command should have been: 

git diff -M --name-status HEAD

This solves the problem of newly added files, but doesn't show 'R' for
renamed files even after I ask git to detect renamed files - just shows that
the renamed file was deleted (doesn't detect that the new renamed file was
added). So I would still appreciate some input here.

Renaming flie:
mv randomfile.xml random.xml

Diffing:
git diff -M --name-status HEAD

Output:
D      randomfile.xml

Thanks, 
jawad

-- 
View this message in context: http://old.nabble.com/How-do-I-get-the-correct-modification-status-after-running-git-diff--tp27782430p27782895.html
Sent from the git mailing list archive at Nabble.com.

```

## Michael J Gruber, 2010-03-04 16:34

Subject: Re: How do I get the correct modification status after running git diff?
Message-ID: <4B8FE121.6040807@drmicha.warpmail.net>
URL: https://gitlist.dev/e/4B8FE121.6040807%40drmicha.warpmail.net
In-Reply-To: <27782895.post@talk.nabble.com>

```
jateeq venit, vidit, dixit 04.03.2010 17:11:
> 
> Ok, so I think I know what I was doing wrong... i wasn't comparing the
> working tree with the last commit (HEAD), although I still don't know what
> exactly I was comparing the working tree with. On reading the manual a

You were comparing the working tree with the index (staging area).

> little more carefully, I realised the command should have been: 
> 
> git diff -M --name-status HEAD
> 
> This solves the problem of newly added files, but doesn't show 'R' for
> renamed files even after I ask git to detect renamed files - just shows that
> the renamed file was deleted (doesn't detect that the new renamed file was
> added). So I would still appreciate some input here.
> 
> Renaming flie:
> mv randomfile.xml random.xml
> 
> Diffing:
> git diff -M --name-status HEAD
> 
> Output:
> D      randomfile.xml

git doesn't know about random.xml here, which you can change like so:

git add -N random.xml

Then git diff -M --name-status HEAD will show the rename.

Alternatively, you could have used "git mv randomfile.xml random.xml"
which would have staged that move in the index already. (More exactly:
the content changes, not the move as such)

Michael

```

## Andreas Schwab, 2010-03-04 16:39

Subject: Re: How do I get the correct modification status after running git diff?
Message-ID: <m2lje8avob.fsf@igel.home>
URL: https://gitlist.dev/e/m2lje8avob.fsf%40igel.home
In-Reply-To: <27782895.post@talk.nabble.com>

```
jateeq <jawad_atiq@hotmail.com> writes:

> Renaming flie:
> mv randomfile.xml random.xml
>
> Diffing:
> git diff -M --name-status HEAD
>
> Output:
> D      randomfile.xml

random.xml is an untracked file, thus ignored.  You need to add -N it
first.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

```
