9

I have the following setup:

  • WSL installed with Ubuntu, with git already installed there
  • git installed from https://git-scm.com on the Windows side
  • Symlink creation enabled by turning on Developer Mode and adding my user to the correct policy group, as explained at https://github.com/git-for-windows/git/wiki/Symbolic-Links
  • core.symlinks=true (due to above line)
  • core.autocrlf=false (I don't want git to do any cleverness, I'm sharing the repo between Windows and WSL)

This almost works perfectly (very impressed). When I clone a repository, it is all okay in both Windows and WSL, apart from the symlinks on one of the two sides say they are modified but they are not. On both sides the symlinks work correctly, I can navigate them without issue.

After an initial clone (on the Windows side), Windows PowerShell gives:

PS C:\Users\Matthew\Projects\...> git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean

However on the WSL side, it says that the two symlinks are modified:

/mnt/c/Users/Matthew/Projects/...$ git status 
On branch master 
Your branch is up to date with 'origin/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:   t/browser 
        modified:   web/jslib

no changes added to commit

But git diff gives no output:

/mnt/c/Users/Matthew/Projects/...$ git diff
/mnt/c/Users/Matthew/Projects/...$ 

If I then reset the checkout on the WSL side, it all switches round:

/mnt/c/Users/Matthew/Projects/...$ git reset --hard HEAD 
HEAD is now at ......... Commit message here
/mnt/c/Users/Matthew/Projects/...$ git status 
On branch master 
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean

And back on Windows Powershell:

PS C:\Users\Matthew\Projects\...> git status
On branch master
Your branch is up to date with 'origin/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:   t/browser
        modified:   web/jslib

no changes added to commit (use "git add" and/or "git commit -a")
PS C:\Users\Matthew\Projects\...> git diff
PS C:\Users\Matthew\Projects\...> 

It seems like git is setting an internal flag that it then considers changed in the other system; is there any way to fix or work around this?

2 Answers 2

10

Found a workaround. I created alias in wsl to Git for windows: alias git="/mnt/c/Program\ Files/Git/bin/git.exe". Works perfect!

1
  • 3
    For those not familiar with bash (me), just put that alias into .bash_aliases file in your ~ (home folder) and it will create that alias on every new session instead of having to do it every time. Commented Dec 30, 2019 at 20:53
7

This issue occurs because Windows and Linux (or at least the emulated version) disagree about the size of a symlink. On Windows, a symlink's size is in blocks, so a 6-character symlink will be 4096 bytes in size. On Linux, a symlink's size is the number of bytes it contains (in this example, 6).

One of the things that Git writes into the index to keep track of whether a file has changed is the size. When you perform any sort of update of the index, such as with git reset --hard, Git writes all of this metadata into the index, including the size. When you run git status, git checks this metadata to determine if it matches, and if not, it marks the file as modified.

It is possible to control whether certain information is checked in the index, since some tools can produce bogus info (for example, JGit doesn't write device and inode numbers), but size is always checked, because it is seen as a good indicator of whether a file has changed.

Since this is a fundamental disagreement between how Windows and how WSL see the symlink, this really can't be fixed. You could try asking the Git for Windows project if they'd be willing to work around this issue in Git for Windows, but I suspect the answer is probably going to be no since changing it would likely have a performance impact for all Windows users.

4
  • 1
    Aha, thanks for the explanation! That's fine, it is not like symlinks are changed very often, I'll mark them as assume-unchanged :) Commented Jun 8, 2019 at 17:08
  • 1
    Could the Linux version of Git be enhanced to check if it is running in the WSL? I assume that it is a Windows system call that says that a symlink is size 4096 bytes. If running in WSL then git could store the length of the path that the symlink points at rather than asking the OS for the length of the symlink file. I expect that most Windows users like the behavior of Git for Windows where it creates a proper Windows symlink that works with other Windows tools. Commented Jan 17, 2020 at 0:54
  • Trying to use assume-unchanged for this is not supported upstream and will break in a variety of ways. The documentation will be updated soon to reflect this.
    – bk2204
    Commented Jan 17, 2020 at 0:57
  • I think it's enormously unlikely that people are going to add portability goop in mainstream Git for this case, especially since every Unix program would have to carry a patch. People are going to want Microsoft to fix their system instead. But you can ask the list or send a patch, and maybe it will happen.
    – bk2204
    Commented Jan 17, 2020 at 0:59

Your Answer

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

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