簡體   English   中英

如何在wsl中克隆git?

[英]How to git clone in wsl?

我嘗試從使用 wsl(Ubuntu 20.04)安裝的全新 Windows 克隆存儲庫。 我做了什么:生成 SSH 密鑰並將公鑰添加到 github 和 framagit。 試過了

ssh -i -T git@github.com

ssh -i -T git@framagit.org

他們倆都說“你好,我的偽君子,你已經被認證了”

但是當我嘗試克隆時,我有以下內容: 沒有 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'

使用須藤:

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專門擁有。

您看到的問題是您在不支持它們的文件系統 (NTFS) 上使用 Linux Git,它期望標准 Unix 權限正常工作。 Git 會在重寫鎖定文件時嘗試適當地設置權限,它將重命名為配置文件的位置,但它不能這樣做,並且失敗。 Windows 的 Git 沒有這個問題,因為它映射這些權限的方式與 WSL 不同,WSL 總是返回錯誤。

你可以嘗試幾件事:

  • 只需在 WSL 下克隆存儲庫,而不是在 Windows 驅動器下。 這保證有效,應該沒問題。
  • 在 WSL 下的某處克隆存儲庫並將其移動到 Windows 驅動器中,或者手動設置 Windows 的配置選項,或者在克隆后在存儲庫中再次嘗試git init
  • Run git init on the Windows drive and then do a git remote add origin YOUR-REMOTE and a git pull origin master (or whatever your branch is called).

最后一個可能不會比現在更好,因為git init可能會以同樣的方式失敗。

您可以按照本指南解決此問題。 總結如下。

從 WSL 提示符:

sudo vim /etc/wsl.conf

添加這些行:

[automount]
options = "metadata"

保存文件,從 PowerShell 提示符關閉 wsl:

wsl --shutdown

重新打開一個 wsl 終端。 您現在應該看到您的用戶擁有的文件,而不是 root。 您現在可以克隆 git、chmod、chown 等。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM