Search code examples
gitmsysgit

`git stash --patch` showing lines changed that `git diff`/`git status` are not showing


When I try to do git stash save --patch I get a lot patch changes that aren't visible in git diff or git status. Each change removes some lines and then reinserts the same lines, without apparent change, e.g.:

-Some text line
+Some text line
-Another line
+Another line

All these changes are in a resource file that hasn't been touched in a while. My platform is Windows using Git for Windows.

Why is git stash showing me different things than git diff and how do I fix this?


Solution

  • This has something to do with the infamous git line endings / core.autocrlf options and the .gitattributes file. Even though I do not understand the cause, I have found the solution for my case.

    It turns out that some git process¹ had created an untracked .gitattributes file in my local repository. Almost all of the lines in this file were commented out, except for near the top it has:

    * text=auto
    

    When I comment out this line, as such

    #* text=auto
    

    the problems with git stash go away and I see only the changes that git diff sees.


    ¹) I suspect the cause was a new Visual Studio C# project I created in the same repository -- I'm guessing the IDE detected the repository and added the file.