Skip to contentSkip to conversation

git diff --name-status does not always list changed files

DISCUSSION Sebastian Schuberth 2 participants 6 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

Hi,

I was getting a lot of "no newline at end of file" warnings with GCC, so I decided to fix these files in my clean working tree with

for i in find . -iname "*.c" -o -iname "*.cc" -o -iname "*.cpp" -o -iname "*.h" -o -iname "*.hpp"; do

    echo $i
    echo wq | ed $i > /dev/null 2>&1

done

Afterwards, I wanted so see a list of files that were actually affected, but to my wonderment "git diff --name-status" did not list any files, although both "git diff" and "gitk" showed the diffs correctly.

Is this a bug in "--name-status" that is does not detected changes if only a final newline has been added, or am I missing something?

Thanks.

Signature · 1 line
Sebastian Schuberth
#1 lore raw
Quoted 5 lines · Sebastian Schuberth

...
so I decided to fix these files in my clean working tree with

for i in find . -iname "*.c" -o -iname "*.cc" -o -iname "*.cpp" -o -iname "*.h" -o -iname "*.hpp"; do

Quoted 8 lines
    echo $i
    echo wq | ed $i > /dev/null 2>&1

done

Afterwards, I wanted so see a list of files that were actually affected, but to my wonderment "git diff --name-status" did not list any files, although both "git diff" and "gitk" showed the diffs correctly.

Doesn't reproduce for me.

        $ rm -fr /var/tmp/j && mkdir -p /var/tmp/j && cd /var/tmp/j
        $ git init
        Initialized empty Git repository in .git/
        $ echo -n hello > world
        $ git add world
        $ od -c world
        0000000   h   e   l   l   o
        0000005
        $ echo wq | ed world
        Newline appended
        6
        6
        $ od -c world
        0000000   h   e   l   l   o  \n
        0000006
        $ git diff --name-status
        M	world
        $ git diff --raw
        :100644 100644 b6fc4c6... 0000000... M	world
        $ exit
#2 lore raw
Quoted 5 lines · Junio C Hamano

Doesn't reproduce for me.

        $ rm -fr /var/tmp/j && mkdir -p /var/tmp/j && cd /var/tmp/j
        $ git init
        Initialized empty Git repository in .git/

Can you reproduce it if you do

$ git config core.pager "less -F"

after "git init"? The "-F" seems to be important, but I'm not sure why using this switch causes no files to be displayed in this case.

Signature · 1 line
Sebastian Schuberth
#3 lore raw
Quoted 8 lines · Sebastian Schuberth
Quoted 5 lines · Junio C Hamano

Doesn't reproduce for me.

        $ rm -fr /var/tmp/j && mkdir -p /var/tmp/j && cd /var/tmp/j
        $ git init
        Initialized empty Git repository in .git/
Quoted 6 lines

Can you reproduce it if you do

$ git config core.pager "less -F"

after "git init"? The "-F" seems to be important, but I'm not sure why using this switch causes no files to be displayed in this case.

Then isn't it what you are asking "less" to do?

Try "less -FX". FYI, by default, we use "LESS=FRSX" exported unless the user knows better than us and uses something of his own.

#4 lore raw
Quoted 12 lines
Quoted 12 lines
Quoted 5 lines · Junio C Hamano

Doesn't reproduce for me.

        $ rm -fr /var/tmp/j && mkdir -p /var/tmp/j && cd /var/tmp/j
        $ git init
        Initialized empty Git repository in .git/

Can you reproduce it if you do

$ git config core.pager "less -F"
Quoted 8 lines
Quoted 2 lines

after "git init"? The "-F" seems to be important, but I'm not sure why using this switch causes no files to be displayed in this case.

Then isn't it what you are asking "less" to do?

Try "less -FX". FYI, by default, we use "LESS=FRSX" exported unless the user knows better than us and uses something of his own.

Thanks, -FX works, though I do not understand why it did not with just -F. From what I understood, -F just makes "less" quit immediately (instead of waiting for the user to press "q") if the lines to display fit completely on screen. In no case it should display nothing if there actually is something to display.

Signature · 1 line
Sebastian Schuberth
#5 lore raw
Quoted 5 lines · Sebastian Schuberth

Thanks, -FX works, though I do not understand why it did not with just -F. From what I understood, -F just makes "less" quit immediately (instead of waiting for the user to press "q") if the lines to display fit completely on screen. In no case it should display nothing if there actually is something to display.

My reading and understanding of less manual page, especially the part that talks about -X suggests that everything is working as it is meant to.

"git diff --name-status" displays something, less shows it, and it quits immediately (because you asked it to with -F). As part of its quitting, it clears the screen because you did not ask less not to do that by giving it an -X.

I am tempted to call it a bug in less, but I am a very nice person and I would not actually do so ;-). But it certainly feels like a misfeature between less and terminfo to me.