简体   繁体   中英

Very strange issue with Git for Windows/WSL2/VS Code

I have Windows 10 and am using VS Code, Git for Windows, and WSL2 with Ubuntu 20.04 LTS (which I access via Windows Terminal).

I needed to reset my computer, so I tar.gz'ed a local repo that I had on my Ubuntu and stored that tar.gz on my secondary drive.

After my reset, I reinstalled all of my apps.

I decompressed my repo back into the same location in Ubuntu, then I did a chown -R gesslar:gesslar /path just to be sure that it had my current IDs on it.

In Windows Terminal, using the WSL2 profile, I cd to the /path and do git status and it says I have no changes to commit.

$ git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean

However, in VS Code, which I access by going to the directory and typing code. in my WSL profile in Windows Terminal, it says that I have 950 pending changes.

在此处输入图像描述

If I use Git Bash, I get a similar reading, and it is showing tonnes of files that are marked as deleted在此处输入图像描述

What's super weird to me is that despite being marked as deleted, the file is actually there. 在此处输入图像描述

And under Untracked files, files that it says are new, don't actually exist.

Please if anybody has ideas on what might be funky about this, I'd appreciate some help. My suspicion is it has something to do with Git for Windows, since I think VS Code is using that to determine changes and it's in Git Bash where I see this weirdness.

Note I know that some may suggest that I just reclone, but my working directory is a copy of production and our.gitignore ignores thousands of data files that I need to work with in my working directory and they're kind of all over the place. Recreating the environment is an absolute last effort, if possible.

This is going to sound really dumb, but, I figured out that hadn't installed the Remote WSL extension for VS Code.

This DOES NOT stop the Git for Windows being confused about what's what, however, it does enable VS Code to use the WSL version of git rather than the Git for Windows.

Therefore, the result is that VS Code is now aware of the actual state of my git repos/working directories within my WSL2 instance.

Thank you for your help, TTT. I really appreciate your responses and I did learn some things from them.

Just one more thing to check, is the line endings. If you're using the same repo in windows and WSL with different git executables, they will get confused and mark files as modified simply because of the line endings being the wrong type for that system. You can avoid that by configuring the line endings in git accordingly .

If you are developing in windows, then git config core.autocrlf true will convert line endings to CRLF (Windows) when the files are checked out.

If you are instead developing in Linux, then git config core.autocrlf input will keep LF endings in the repo and Linux system but at the same time leave CRLF line ends in Windows checkouts.

Those settings you can also set them globally by adding the --global option.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM