当我尝试使用GUI工具将虚拟环境和GitHub连接起来时,遇到了一些困难的经历
环境
-
- Windows11
-
- wsl(Ubuntu)
-
- Git 2.25.1
-
- Soucetree
- Gitドドド初心者
发生的事情
当我试图通过Soucetree从GitHub克隆存储库到Ubuntu内的sunaba01目录时,发生了以下错误。
'git status' がコード 128 で終了しました: fatal: detected dubious ownership in repository at '//wsl.localhost/Ubuntu-20.04/home/***/sunaba01'
To add an exception for this directory, call:
git config --global --add safe.directory '%(prefix)///wsl.localhost/Ubuntu-20.04/home/***/sunaba01'
(\\wsl.localhost\Ubuntu-20.04\home\***\sunaba01)

导致这个情况的根本原因。
听说是由Git 2.35.2版本引入的safe.directory的影响。
解决方案
就拿我自己作为例子,我试过以下命令,但有的可以解决问题,有的则无法解决(在“再次发生”部分进行记录)。
git config --global --add safe.directory "'%(prefix)///wsl.localhost/Ubuntu-20.04/home/*'"
由于每次都要单独设置目录而感到麻烦,所以我将home目录及其子目录都注册在safe.directory中,并设置为允许访问的配置。
在这种情况下,如果将路径指定为’%(prefix)///wsl.localhost/Ubuntu-20.04/home/*’并仅使用单引号,会导致无法正常运行。
验证
在设定正常目录后,确认已正确设置。
$ git config --global -l
color.diff=auto
color.status=auto
color.branch=auto
safe.directory=%(prefix)///wsl.localhost/Ubuntu-20.04/home/*
safe.directory='%(prefix)///wsl.localhost/Ubuntu-20.04/home/*'
如果存在 safe.directory=’%(prefix)///wsl.localhost/Ubuntu-20.04/home/*’,那就没问题。
管理的领域
因为我是Git的初学者,所以在排除原因之前,我认为是依赖于虚拟环境而不是版本的错误,使我苦苦挣扎。
当我搜索错误信息时,很快就找到了答案,为了以后学习的需要,我会留下这篇文章。
-
- Ubuntu(WSL)の git をアップデートする
- Getting code 128: fatal: detected dubious ownership in repository
再次发生
一旦解决了错误,问题又出现了。原因是在虚拟环境中,而不是在虚拟环境的Git,而是在尝试访问虚拟环境的Windows Git。所以,我修改了Windows Git的safe.directory。由于这次只有我一个人在使用,我将设置允许所有文件的权限。(在Windows的CUI中,使用PowerShell)
git config --global -e
配置文件内
[safe]
directory = *
只要删除虚拟环境中的safe.directory,问题就可以解决。
通过在Windows上安装的Git GUI成功进行了GitHub管理。非常感谢在Twitter上发出求助声音后受到帮助的FireFox内的专家。