'git status' shows changed files, but 'git diff' doesn't

前端 未结 15 1854
轻奢々
轻奢々 2020-12-12 11:37

I\'ve had a look at all similar questions. However, I\'ve double checked and something strange is definitely happening.

On one server (Solaris with Git 1.8.1) I clon

相关标签:
15条回答
  • 2020-12-12 11:57

    I added the file to the index:

    git add file_name
    

    and then ran:

    git diff --cached file_name
    

    You can see the description of git diff here.

    If you need to undo your git add, then please see here: How to undo 'git add' before commit?

    0 讨论(0)
  • 2020-12-12 11:58

    I stumbled upon this problem again. But this time it occurred for a different reason. I had copied files into the repo to overwrite the previous versions. Now I can see the files are modified but diff doesn't return the diffs.

    For example, I have a mainpage.xaml file. In File Explorer I pasted a new mainpage.xaml file over the one in my current repo. I did the work on another machine and just pasted the file here.

    The file shows modified, but when I run git diff, it will not show the changes. It's probably because the fileinfo on the file has changed and git knows that it isn't really the same file. Interesting.

    You can see that when I run diff on the file it shows nothing, just returns the prompt.

    0 讨论(0)
  • 2020-12-12 12:01

    There are a few reasons why git status might show a difference but git diff might not.

    • The mode (permission bits) of the file changed-- for example, from 777 to 700.

    • The line feed style changed from CRLF (DOS) to LF (UNIX)

    The easiest way to find out what happened is to run git format-patch HEAD^ and see what the generated patch says.

    0 讨论(0)
  • 2020-12-12 12:01

    I've just run in a similar issue. git diff file showed nothing because I added file to the Git index with some part of its name in uppercase: GeoJSONContainer.js.

    Afterwards, I've renamed it to GeoJsonContainer.js and changes stopped being tracked. git diff GeoJsonContainer.js was showing nothing. I had to remove the file from the index with a force flag, and add the file again:

    git rm -f GeoJSONContainer.js
    git add GeoJSONContainer.js
    
    0 讨论(0)
  • 2020-12-12 12:02

    I had a similar problem: git diff would show differences, but git diff <filename> would not. It turned out that I set LESS to a string including -F (--quit-if-one-screen). Removing that flag solved the problem.

    0 讨论(0)
  • 2020-12-12 12:04

    I ran into this problem. My case was similar to the LESS issue posted by rcwxok.

    In my case, I set the PAGER environment variable to PAGER='less -RSF'.

    However, unlike the previous answers, I didn't want to remove the -F option, because I explicitly put it there hoping to prevent showing the diff in less if it's shorter than a screenful.

    To get the desired result, instead of removing -F, I added -X: PAGER='less -RSFX'. This both solved the git diff issue and in addition it prevents showing short diffs with less.

    0 讨论(0)
提交回复
热议问题