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:
Below is a git diff
on one of the files
Now if I run a git status
on the exact same repository on the Windows side (through powershell), I get nothing:
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.
Git can be installed on Windows AND on WSL An important consideration: when you enable WSL and install a Linux distribution, you are installing a new file system, separated from the Windows NTFS C:\ drive on your machine.
WSL is better in that it's a full Linux system running on a real Linux kernel managed by Windows inside the Hyper-V hypervisor. Git Bash is just a shell and it's still running on Windows, which is better for Windows integration. That depends entirely on you.
There are two methods to launch git in windows. One is launching git using a bash scripting shell with the help of the command line and another is launching git using a graphical user interface. To launch git via bash scripting shell, First, open the window and search for git bash and open it.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With