Herman Autore
Herman Autore

Reputation: 180

Why can't VSCode visualize `git` differences from files on a shared drive?

I use VSCode for editing files both on my local drive and on a shared drive. However, I've noticed that VSCode frequently does not visualize the diffs for files on the shared drive. Is this a known issue? How can I troubleshoot this?

I've tried restarting VSCode, and the Git built-in to no avail.

Let me know if there's any environment or system specifications I can share here to shed more light.

Upvotes: 0

Views: 100

Answers (1)

Herman Autore
Herman Autore

Reputation: 180

The solution was to use git config --global core.autocrlf true. This is a possible duplicate of this post.

I'm answering my own question starting with a correction. I thought was VSCode not visualizing differences because I saw files in the source control tab, with the "M" tag, but didn't see any diff highlighting (e.g., green, or red). But in reality VSCode was not wrong, because the diff was just one character, ^M. I realized this when I did git diff HEAD:filea filea and noticed the entire file was red (-) and again in green (+). The difference between the original and new versions was that each line was appended with a ^M character.

According to this Unix.SE post the ^M character appears when files originating from Windows systems are read by Unix-like systems. My files are originating from a shared drive, which may or may not be Windows-based.

I troubleshooted by situation further by using git diff HEAD:fileb fileb, where fileb is a file I had modified, and again the entire original file was in red (-) and the new version was in green (+), including the ^M characters. When I ran git diff --ignore-cr-at-eol HEAD:fileb fileb it showed the correct highlighting, with only the deleted parts in red (-) and the added parts in green (+).

Although this fixed everything on the command life for git, VSCode was still tracking the files as modified. However, when I ran git config --global core.autocrlf true, then all the files that were being tracked just for the ^M characters were removed from the version control tab. Note, however, that before changing git config I tried to fix the files manually by changing the EOL on VSCode from "CRLF" to "LF", and this change was reflected on the git command line but not VSCode. Only changing Git's config fixed the issue on the command line and on VSCode.

Upvotes: 0

Related Questions