Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git repo gives contradictory info from WSL than from Windows

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.

like image 922
James Wright Avatar asked Dec 23 '18 02:12

James Wright


People also ask

Does git for Windows use WSL?

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.

Is git Bash same as WSL?

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.

Does git work with Windows?

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.


1 Answers

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

like image 142
Joe Hickey Avatar answered Sep 27 '22 20:09

Joe Hickey