33

When I run git status on a git repository through WSL (Windows Subsystem for Linux) that's on the Window's directory (/mnt/c/Users/....), I get that every file in the directory has been modified. Each modification is just delete and re-write of the original file. See below: enter image description here

Below is a git diff on one of the files git diff on specific file

Now if I run a git status on the exact same repository on the Windows side (through powershell), I get nothing:

enter image description here

Any particular reason behind this? I know the ^M have to do with the different line endings that Linux and Microsoft are using, but that git would disagree on whether changes have been made or not seems odd to me.

Note: I've been working on the repository on WSL side through a separate clone of the repository (hence why the Windows side is 15 commits behind). No editing has been done to the Windows repository though. Not sure if this changes anything, but I'd figure I'd mention it.

2
  • 1
    I would tend to agree that this almost certainly has to do with the line ending/crlf setting. What is setting for core.autocrlf?
    – Joe Hickey
    Dec 23, 2018 at 2:53
  • On the powershell side, it's set to true. On the WSL side, it's not set. Dec 23, 2018 at 3:01

2 Answers 2

42

The two git installations (native windows and WSL) are using a different setting for the core.autocrlf configuration, because these two installations are not using the same global config file.

Put simply, the native windows client is converting LF to CRLF upon checkout, and hence the presence of CRLF is not "seen" as a change by git status. On the contrary, the WSL client expects UNIX-style LF line endings, so the git status sees every file as having been modified to change LF to CRLF.

Instead of relying on the global setting the core.autocrlf you should set it locally in the repository for any shared repositories. If the same repository is being accessed from both Linux/WSL and native Windows, you probably want this set to false so git does not change any line endings at all. Just beware that if you do set this as false, you'll have to make sure your editors can handle the line endings as they are (in general, most programmers editors I've used do support using UNIX LF, even on Windows).

The core.autocrlf is documented here for more info:

https://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration#_core_autocrlf

4
  • Good job man - thank you very much :) I had no idea that this was an issue at all.. It seems kinda stupid :) Nov 25, 2019 at 9:14
  • 4
    I have set core.autocrlf in WSL environment to true to mimic the behavior of Windows (as the IDEs run in Windows as well). That might be an option as well. On a fresh system starting with it OFF and simple using LF might be better (and every IDE supports that) but I did not want to disturb the existing repo...
    – ZoolWay
    Apr 15, 2020 at 12:41
  • I use autocrlf:false, see my comment to this post
    – Timo
    Jun 4, 2021 at 6:00
  • I wonder if it would be possible to set this automatically based on the file path? I would prefer if all my repos under /mnt/c/ automatically used windows line endings even in WSL, and all repos under the WSL filesystem used unix line endings. Aug 12 at 20:29
6

This could have something to do with WSL reporting the permissions of all files on the Windows filesystem as being 777. Git then regards all files as changed because their permissions are different.

Try changing the Git configuration so that permission changes are ignored:

# For the current repository
git config core.filemode false   

# Globally
git config --global core.filemode false

See: https://github.com/microsoft/WSL/issues/184

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.