Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Windows上的Ubuntu(WSL)上使用Git和VS代码以及Bash_Git_Visual Studio Code_Vscode Settings_Windows Subsystem For Linux_Bash On Windows - Fatal编程技术网

在Windows上的Ubuntu(WSL)上使用Git和VS代码以及Bash

在Windows上的Ubuntu(WSL)上使用Git和VS代码以及Bash,git,visual-studio-code,vscode-settings,windows-subsystem-for-linux,bash-on-windows,Git,Visual Studio Code,Vscode Settings,Windows Subsystem For Linux,Bash On Windows,我不知道如何将WSL与VS代码集成。我可以使用以下方法打开集成终端: "terminal.integrated.shell.windows": "C:\\Windows\\sysnative\\bash.exe" 集成终端工作。但是,我不能使用源代码管理或VS代码的任何linting特性。在源代码管理菜单中,它显示“没有活动的源代码管理提供程序” 这个问题可能是由git的路径引起的,但我不知道如何解决这个问题。我将感谢任何帮助。谢谢。您需要在主机操作系统(Windows)上安装Git,因为VS

我不知道如何将WSL与VS代码集成。我可以使用以下方法打开集成终端:

"terminal.integrated.shell.windows": "C:\\Windows\\sysnative\\bash.exe"
集成终端工作。但是,我不能使用源代码管理或VS代码的任何linting特性。在源代码管理菜单中,它显示“没有活动的源代码管理提供程序”


这个问题可能是由git的路径引起的,但我不知道如何解决这个问题。我将感谢任何帮助。谢谢。

您需要在主机操作系统(Windows)上安装Git,因为VS代码从cmd调用Git,而不是集成终端

这个问题的解决方案是安装git for Windows。是一个很好的选择。

根据需要,您必须编写批处理文件

@echo off
bash.exe -c "git %*"
并告诉VsCode git插件以该bat文件为目标。(终端设置为与您一样使用bash)

您可以为所有linter/sniffer/helpers插件执行此操作


希望这能帮助。。。和工作;-)

这些选项对我都不起作用,所以我建立了自己的

您可以在这里找到我的完整解决方案:

简而言之:您需要通过批处理文件(如建议的)进行代理,但是当与VSC一起使用时,它们的批处理文件将失败,因为它无法正确地转义代理命令,并且无法转换与Windows和Unix之间的路径


为了子孙后代,以下是我在发布本文时链接的脚本,sans ReadMe:

git.bat

@echo off

:: %~dp0 is the directory of this batch file
set proxy_path=%~dp0_proxy_cmd.bat
:: %* is the full command passed to this batch file
%proxy_path% git %*
@echo off

:: Properly escape the command
:: Many thanks to wsl-alias for this logic: https://github.com/leongrdic/wsl-alias
set cmd=%*
set cmd=%cmd:\"=\\"%
set cmd=%cmd:\'=\\'%
set cmd=%cmd:\=/%
set cmd=%cmd://=\\%
set cmd=%cmd:"=\"%
set cmd=%cmd:'=\'%
set cmd=%cmd:(=\(%
set cmd=%cmd:)=\)%

:: Grab the path to our proxy Bash script (%~dp0 is the directory of this batch file)
set bash_proxy=%~dp0_proxy_cmd.sh
set bash_proxy=%bash_proxy:\=\\%

:: Pass things off to the Bash script
bash.exe -c "$(wslpath %bash_proxy%) %cmd%"
\u proxy\u cmd.bat

@echo off

:: %~dp0 is the directory of this batch file
set proxy_path=%~dp0_proxy_cmd.bat
:: %* is the full command passed to this batch file
%proxy_path% git %*
@echo off

:: Properly escape the command
:: Many thanks to wsl-alias for this logic: https://github.com/leongrdic/wsl-alias
set cmd=%*
set cmd=%cmd:\"=\\"%
set cmd=%cmd:\'=\\'%
set cmd=%cmd:\=/%
set cmd=%cmd://=\\%
set cmd=%cmd:"=\"%
set cmd=%cmd:'=\'%
set cmd=%cmd:(=\(%
set cmd=%cmd:)=\)%

:: Grab the path to our proxy Bash script (%~dp0 is the directory of this batch file)
set bash_proxy=%~dp0_proxy_cmd.sh
set bash_proxy=%bash_proxy:\=\\%

:: Pass things off to the Bash script
bash.exe -c "$(wslpath %bash_proxy%) %cmd%"
\u proxy\u cmd.sh

##
# Evaluates command, parsing paths at both ends (Windows => Unix => Windows)
#
# Benefits to doing this instead of directly invoking the command in the batch file:
# 
# + Easier to convert path arguments to Unix paths
# + sed regex does not require double escaping backslashes (not embedded in double quotes)
##

cmd=()
for arg in "$@"
do
    if [[ $arg =~ ^[a-zA-Z]:/ ]]; then
        cmd+=( $(wslpath "$arg") )
    else
        cmd+=("$arg")
    fi
done

# TODO: Look into ways to convert inline paths via `wslpath` instead of hard-coding `/mnt` search
# Kind of a tricky issue, because our output could be basically anything
eval "${cmd[@]}" | sed \
    -e 's|"/mnt/\([a-zA-Z]\)/\([^"]*\)"|"\1:/\2"|g' \
    -e "s|'/mnt/\\([a-zA-Z]\\)/\\([^']*\\)'|'\\1:/\\2'|g" \
    -e 's|/mnt/\([A-Za-z]\)/\([^ ]*\)|\1:/\2|g' \
    -e 's|/|\\|g'

Linting和源代码控制是两个截然不同的问题。Git是否安装在您的系统上,是否与GitHub Desktop或类似软件一起安装?Git是否安装在WSL上?@ifconfig是,但未安装在Windows上。请尝试安装GitHub Desktop。您所在的文件夹是否已配置为git repo?@ifconfig当我在Windows上下载git时,问题没有发生。我现在就坚持使用PowerShell。谢谢你的帮助。