VSCode + WSL Remote + Git :同步更改需要永远
VSCode + WSL Remote + Git : Synchronizing changes take forever
我正在 VSCode 远程使用我位于(符号链接)到 WSL 2 VM 中的项目文件夹。我使用 SSH 和终端从 Bitbucket 克隆了我的存储库。
在左下角,它显示WSL: Ubuntu
,所以我目前正在远程使用它。一切顺利
如果我单击 Git 分支指示器,我可以看到本地分支和远程分支。一切顺利
问题是当我在本地提交后单击以同步所有内容时,它永远旋转。好吧,不是真的,我在永远发生之前就失去了耐心...当前测试大约 30 分钟。
如果我 git push
进入终端,一切都会按预期进行。
有人知道它为什么这样做吗?我该如何解决这个问题?
我的Git输出成VSCode不断return这个git rev-parse --show-toplevel
?
我为 user.name 和 user.email
做了 git config
SSH 密钥在 Bitbucket 上设置。 Windows 和 WSL 2 使用相同的 public/private 密钥。
谢谢
2021-02-05 更新
这个问题最近有很多意见,我觉得我需要给出更透彻的解释。最初的答案是在 WSL 2 仍处于测试阶段时编写的。现在一切都在发展,从 SSH 密钥中删除密码可能会导致一些漏洞。所以,在进一步讨论之前,先看看这个 post Is it okay to use a SSH key with an empty passphrase?
问问自己删除它是否安全。
不知道原来的问题还有没有。写完题不久我就放弃了WSL for web dev
原答案
我解决了我的问题。因此,对于那些想尝试 WSL 2 并遇到此问题的人来说,问题是 SSH 密钥的密码短语。
Resolving hangs when doing a Git push or sync on an SSH host
If you clone a Git repository using SSH and your SSH key has a passphrase, VS Code's pull and sync features may hang when running remotely.
Either use an SSH key without a passphrase, clone using HTTPS, or run git push from the command line to work around the issue.
如果您想删除您的密码,请使用 $ ssh-keygen -p
,如该问题中所述:
宁愿从命令行进行推送和拉取,也不愿删除密码!
您也可以使用 ssh-agent 来解决这个问题。
将以下内容添加到您的 ~/.bashrc 中,每当您打开终端时,系统都会提示您解锁密钥(如果未解锁)。
env=~/.ssh/agent.env
agent_load_env () { test -f "$env" && . "$env" >| /dev/null ; }
agent_start () {
(umask 077; ssh-agent >| "$env")
. "$env" >| /dev/null ; }
agent_load_env
# agent_run_state: 0=agent running w/ key; 1=agent w/o key; 2= agent not running
agent_run_state=$(ssh-add -l >| /dev/null 2>&1; echo $?)
if [ ! "$SSH_AUTH_SOCK" ] || [ $agent_run_state = 2 ]; then
agent_start
ssh-add
elif [ "$SSH_AUTH_SOCK" ] && [ $agent_run_state = 1 ]; then
ssh-add
fi
unset env
此外,您可以配置添加到 ssh-agent 的密钥的到期时间,如下所示 - https://unix.stackexchange.com/questions/122511/configuring-the-default-timeout-for-the-ssh-agent
在这种情况下删除密码是最简单的选择,但您也可以查看相关问题:microsoft/vscode-remote-release
issue 2369
它包括一个recent workaround (Feb. 2021) found by Elsie Hupp:
I figured out a potential workaround: SSH Agent Forwarding.
In your SSH config, for the remote VS Code host, add the following:
ForwardAgent yes
(The indentation is important.)
For me, the host set up to SSH into with VS Code is called alpha, so the section of the file looks like this:
Host alpha
ForwardAgent yes
If you want to do this with all remote hosts, you can add it to the Host *
section (though this is apparently a marginal security risk):
Host *
ForwardAgent yes
What this does is it uses the SSH agent that you're using to connect to the remote host and recycles the SSH keys for any SSH connections from the remote, such as connecting to Git.
Because VS Code will happily prompt you for your SSH key's passphrase when you're connecting to a VS Code remote, you can enter the passphrase when initially connecting and not have to re-enter it when interacting with Git.
Apparently you can use more than one local SSH key when agent-forwarding, but I haven't been able to test this. I haven't been able to test this, in general, yet, but it seems promising.
我正在 VSCode 远程使用我位于(符号链接)到 WSL 2 VM 中的项目文件夹。我使用 SSH 和终端从 Bitbucket 克隆了我的存储库。
在左下角,它显示WSL: Ubuntu
,所以我目前正在远程使用它。一切顺利
如果我单击 Git 分支指示器,我可以看到本地分支和远程分支。一切顺利
问题是当我在本地提交后单击以同步所有内容时,它永远旋转。好吧,不是真的,我在永远发生之前就失去了耐心...当前测试大约 30 分钟。
如果我 git push
进入终端,一切都会按预期进行。
有人知道它为什么这样做吗?我该如何解决这个问题?
我的Git输出成VSCode不断return这个git rev-parse --show-toplevel
?
我为 user.name 和 user.email
做了 git config
SSH 密钥在 Bitbucket 上设置。 Windows 和 WSL 2 使用相同的 public/private 密钥。
谢谢
2021-02-05 更新
这个问题最近有很多意见,我觉得我需要给出更透彻的解释。最初的答案是在 WSL 2 仍处于测试阶段时编写的。现在一切都在发展,从 SSH 密钥中删除密码可能会导致一些漏洞。所以,在进一步讨论之前,先看看这个 post Is it okay to use a SSH key with an empty passphrase?
问问自己删除它是否安全。
不知道原来的问题还有没有。写完题不久我就放弃了WSL for web dev
原答案
我解决了我的问题。因此,对于那些想尝试 WSL 2 并遇到此问题的人来说,问题是 SSH 密钥的密码短语。
Resolving hangs when doing a Git push or sync on an SSH host
If you clone a Git repository using SSH and your SSH key has a passphrase, VS Code's pull and sync features may hang when running remotely.
Either use an SSH key without a passphrase, clone using HTTPS, or run git push from the command line to work around the issue.
如果您想删除您的密码,请使用 $ ssh-keygen -p
,如该问题中所述:
宁愿从命令行进行推送和拉取,也不愿删除密码!
您也可以使用 ssh-agent 来解决这个问题。
将以下内容添加到您的 ~/.bashrc 中,每当您打开终端时,系统都会提示您解锁密钥(如果未解锁)。
env=~/.ssh/agent.env
agent_load_env () { test -f "$env" && . "$env" >| /dev/null ; }
agent_start () {
(umask 077; ssh-agent >| "$env")
. "$env" >| /dev/null ; }
agent_load_env
# agent_run_state: 0=agent running w/ key; 1=agent w/o key; 2= agent not running
agent_run_state=$(ssh-add -l >| /dev/null 2>&1; echo $?)
if [ ! "$SSH_AUTH_SOCK" ] || [ $agent_run_state = 2 ]; then
agent_start
ssh-add
elif [ "$SSH_AUTH_SOCK" ] && [ $agent_run_state = 1 ]; then
ssh-add
fi
unset env
此外,您可以配置添加到 ssh-agent 的密钥的到期时间,如下所示 - https://unix.stackexchange.com/questions/122511/configuring-the-default-timeout-for-the-ssh-agent
在这种情况下删除密码是最简单的选择,但您也可以查看相关问题:microsoft/vscode-remote-release
issue 2369
它包括一个recent workaround (Feb. 2021) found by Elsie Hupp:
I figured out a potential workaround: SSH Agent Forwarding.
In your SSH config, for the remote VS Code host, add the following:
ForwardAgent yes
(The indentation is important.)
For me, the host set up to SSH into with VS Code is called alpha, so the section of the file looks like this:
Host alpha ForwardAgent yes
If you want to do this with all remote hosts, you can add it to the
Host *
section (though this is apparently a marginal security risk):Host * ForwardAgent yes
What this does is it uses the SSH agent that you're using to connect to the remote host and recycles the SSH keys for any SSH connections from the remote, such as connecting to Git.
Because VS Code will happily prompt you for your SSH key's passphrase when you're connecting to a VS Code remote, you can enter the passphrase when initially connecting and not have to re-enter it when interacting with Git.Apparently you can use more than one local SSH key when agent-forwarding, but I haven't been able to test this. I haven't been able to test this, in general, yet, but it seems promising.