Git status shows modified files, but git diff is not

I looked at all the similar questions, however I checked twice, and something strange is definitely happening.

On one server (Solaris with git 1.8.1), I cloned the git repository and then copied the .git folder to my existing real-time files. It worked fine, I could run

git status 

then

 git diff [filename] 

to check for any files that were different.

On another server (Solaris with git 1.7.6) I am doing the same thing, but

 git diff [filename] 

shows nothing, even if the contents of the file are definitely different. I also tested adding a new file, and then edited it. The same problem, git status shows the file as modified, but git diff shows nothing. If I download the modified file and run diff locally, I get a diff output.

+141
git diff
Jan 28 '13 at 15:10
source share
13 answers

I added the file to index :

 git add file_name 

and then do:

 git diff --cached file_name 

Here you can see a description of git diff.

If you need to undo the addition of git, see here: How to undo the 'git add' before committing?

+64
Feb 10 '15 at
source share

There are several reasons why git status may show a difference, but git diff may not be.

  • The mode (resolution bit) of the file is changed - for example, from 777 to 700.

  • Translation line 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.

+52
Jun 27 '13 at 17:25
source share

For me, this had something to do with file permissions. Someone with Mac / Linux in my project seems to be committing some files with permissions other than the default settings that my Windows git client could not play. The solution for me was to tell git to ignore file permissions:

 git config core.fileMode false 

Another understanding: How do I change git to ignore file mode (chmod)?

+44
Aug 13 '15 at 11:09
source share

I had a problem where several versions of strings were changed by some programs, and git diff listed all the source files as changed. After fixing the line endings, git status still listed the files as changed.

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

 git add -A git reset 

core.filemode set to false.

+32
Sep 27 '16 at 8:13
source share

I suspect something is wrong with your git installation or with your repository.

Try to run:

 GIT_TRACE=2 git <command> 

See if you get anything useful. If this does not help, just hide and see what is going wrong:

 strace git <command> 
+17
Feb 20 '13 at 12:44
source share

I had a similar problem: git diff will show the differences, but git diff <filename> will not. It turned out that I installed LESS on a line containing -F ( --quit-if-one-screen ). Removing this flag solved the problem.

+10
Oct 21 '14 at 19:59
source share

Let's move on to this problem. My case was similar to a LESS question posted by @rcwxok.

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

However, unlike previous answers, I did not want to remove the -F option, because I explicitly put it there, hoping to prevent diff from showing in LESS if it is shorter than the screen.

To get the desired result, instead of removing -F I added -X : PAGER='less -RSFX' . This solved the git diff problem, and in addition, it prevents the display of short differences using LESS .

Hope this helps someone.

+5
Nov 06 '16 at 10:43
source share

Short answer

Sometimes git add works.

Example

Git status shows modified files, and git diff shows 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 inconsistency.

 > git add > git status On branch master nothing to commit, working directory clean > 
+4
Apr 21 '16 at 20:06
source share

I just ran into a similar problem. git diff file showed nothing, because I added the file to the git index with some part of its name in upper case: GeoJSONContainer.js . Subsequently, I renamed it to GeoJSONContainer.js , and the changes were no longer tracked. git diff GeoJsonContainer.js didn't show anything. To remove a file from the index using the force flag and add the file again:

 git rm -f GeoJSONContainer.js git add GeoJSONContainer.js 
+3
Aug 09 '16 at 9:58 on
source share

You really did not ask the actual question, but since this is a common precedent, I often use what I do here. You can try it yourself and see if the error persists.

My assumption about your use case: You have an existing directory containing files and directories, and now you want to convert it to a git repository that is cloned from somewhere else, without changing any data in your current directory.

There are two ways.

Clone repo - mv .git - git reset --hard

This method is what you did - clone an existing repo into an empty directory, and then move the .git directory to the target directory. To work without problems, you usually need to run

 git reset --hard 

However, this will change the state of the files in your current directory. You can try this on a full copy of / rsync of your directory and examine what changes. At least after this you should no longer see the discrepancy between git log and status .

Initiate a new repo - point to the origin

The second less worries: cd to the destination and launches a new repo with

 git init 

Then you will say that the new repo, that it has an ancestor somewhere else:

 git remote add origin original_git_repo_path 

Then safe

 git fetch origin master 

to copy data without changing local files. Everything should be fine now.

I always recommend the second way to reduce the chance of errors.

+2
Feb 19 '13 at 15:27
source share

I had the same problem, described as follows: If I typed

 $ git diff 

git just returns to the prompt without errors.

If i typed

 $ git diff <filename> 

git just returns to the prompt without errors.

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

Here's the deal. I run windows and installed another bash utility, and it changed my path so that it no longer points 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 file that git runs is located in your mingw64 \ bin directory

Finally, to fix this, I actually copied the mingw64 \ bin directory to the git folder that was looking for it. I tried it, but it still didn't work.

Then I closed the git bash window and opened it again, switched to the same repo that didn't work, and now it works.

Hope this helps too.

+1
Sep 11 '15 at 21:15
source share

I came across this problem again. But this time it happened for another reason. I copied the files to the repo to overwrite previous versions. Now I see that the files are changed, but diff does not return diff.

For example, I have a mainpage.xaml file. In File Explorer, I inserted a new mainpage.xaml file on top of the one in my current repo. I did the work on another machine and just attached the file here. git shows modified

The file appears modified, but when I run git diff, it will not show the change. Probably because the fileinfo in the file has changed and git knows that this is not the same file. Interesting.

git diff shows nothing

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

+1
Sep 15 '16 at 1:58
source share

As noted above , this situation may occur due to line termination problems (CRLF vs. LF). I solved this problem (in git version 2.22.0) with this command:

 git add --renormalize . 

According to instructions:

  --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
Jul 15 '19 at 14:00
source share



All Articles