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

前端 未结 15 1855
轻奢々
轻奢々 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 12:05

    I had an issue where hundreds of line endings were modified by some program and git diff listed all source files as changed. After fixing the line endings, git status still listed the files as modified.

    I was able to fix this problem by adding all files to the index and then resetting the index.

    git add -A
    git reset
    

    core.filemode was set to false.

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

    I suspect there is something wrong either with your Git installation or your repository.

    Try running:

    GIT_TRACE=2 git <command>
    

    See if you get anything useful. If that doesn't help, just use strace and see what's going wrong:

    strace git <command>
    
    0 讨论(0)
  • 2020-12-12 12:07

    I used git svn, and had this problem for one file. Using ls-tree for each ancestor of the file, I noticed that one had 2 subfolders - Submit and submit. Since I was on Windows, they couldn't both be checked out, causing this issue.

    The solution was to delete one of them directly from TortoiseSVN Repo-browser, then to run git svn fetch followed by git reset --hard origin/trunk.

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

    Short Answer

    Running git add sometimes helps.

    Example

    Git status is showing changed files and git diff is showing nothing...

    > git status
    On branch master
    Changes not staged for commit:
      (use "git add <file>..." to update what will be committed)
      (use "git checkout -- <file>..." to discard changes in working directory)
    
            modified:   package.json
    
    no changes added to commit (use "git add" and/or "git commit -a")
    > git diff
    > 
    

    ...running git add resolves the inconsistency.

    > git add
    > git status
    On branch master
    nothing to commit, working directory clean
    > 
    
    0 讨论(0)
  • 2020-12-12 12:11

    As already noted in a previous answer, this situation may arise due to line-ending problems (CR/LF vs. LF). I solved this problem (under Git version 2.22.0) with this command:

    git add --renormalize .
    

    According to the manual:

           --renormalize
               Apply the "clean" process freshly to all tracked files to
               forcibly add them again to the index. This is useful after
               changing core.autocrlf configuration or the text attribute in
               order to correct files added with wrong CRLF/LF line endings.
               This option implies -u.
    
    0 讨论(0)
  • 2020-12-12 12:16

    I had this same problem described in the following way: If I typed

    $ git diff
    

    Git simply returned to the prompt with no error.

    If I typed

    $ git diff <filename>
    

    Git simply returned to the prompt with no error.

    Finally, by reading around I noticed that git diff actually calls the mingw64\bin\diff.exe to do the work.

    Here's the deal. I'm running Windows and had installed another Bash utility and it changed my path so it no longer pointed to my mingw64\bin directory.

    So if you type:

    git diff
    

    and it just returns to the prompt you may have this problem.

    The actual diff.exe which is run by git is located in your mingw64\bin directory

    Finally, to fix this, I actually copied my mingw64\bin directory to the location Git was looking for it in. I tried it and it still didn't work.

    Then, I closed my Git Bash window and opened it again went to my same repository that was failing and now it works.

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