Windows 如何在wsl中进行git克隆?

Windows 如何在wsl中进行git克隆?,windows,git,windows-subsystem-for-linux,Windows,Git,Windows Subsystem For Linux,我试图从一个全新的Windows安装wsl(Ubuntu 20.04)中克隆一个repo。 我所做的:生成SSH密钥并将公钥添加到github和framagit。 尝试 及 两人都说:“你好,我的伪小子,你被认证了” 但当我尝试克隆时,我有以下几点: 没有sudo: Cloning into 'testaaa'... error: chmod on /mnt/d/dev/dev/testaaa/.git/config.lock failed: Operation not permitted fa

我试图从一个全新的Windows安装wsl(Ubuntu 20.04)中克隆一个repo。 我所做的:生成SSH密钥并将公钥添加到github和framagit。 尝试

两人都说:“你好,我的伪小子,你被认证了”

但当我尝试克隆时,我有以下几点: 没有sudo:

Cloning into 'testaaa'...
error: chmod on /mnt/d/dev/dev/testaaa/.git/config.lock failed: Operation not permitted
fatal: could not set 'core.filemode' to 'false'
对于sudo:

Cloning into 'testaaa'...
ssh: connect to host framagit.org port 22: Network is unreachable
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.

我能做些什么来解决我的问题呢?

你不想在这里使用
sudo
,一般来说,没有理由在Git中使用它,除非你使用的存储库是由
root
专门拥有的

您看到的问题是,在不支持标准Unix权限的文件系统(NTFS)上使用的是Linux Git。Git在重写锁文件(它将把锁文件重命名为配置文件)时,会尝试适当地设置权限,但是它不能这样做,并且失败了。Git for Windows没有这个问题,因为它映射这些权限不同于WSL,WSL总是返回错误

您可以尝试以下几种方法:

  • 只需在WSL下而不是在Windows驱动器下克隆存储库。这是保证工作,应该是罚款
  • 将存储库克隆到WSL下的某个位置,并将其移动到Windows驱动器中,可以手动设置Windows的配置选项,也可以在克隆后在存储库中再次尝试
    git init
  • 在Windows驱动器上运行
    git init
    ,然后执行
    git-remote-add-origin-YOUR-remote
    git-pull-origin-master
    (或调用分支的任何操作)

最后一个可能不会比现在更好,因为
git init
可能会以同样的方式失败。

我可以使用WSL将git克隆到共享NTFS文件系统中。微软可能已经修复了它们的实现,从而使
chmod
不再损坏。或者它可能在WSL 1和WSL 2下表现不同。答案仍然是一样的:在OP的情况下,文件系统不支持
chmod
,并返回一个错误,Git失败。
Cloning into 'testaaa'...
error: chmod on /mnt/d/dev/dev/testaaa/.git/config.lock failed: Operation not permitted
fatal: could not set 'core.filemode' to 'false'
Cloning into 'testaaa'...
ssh: connect to host framagit.org port 22: Network is unreachable
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.