Azure Blob Storage
中存储的 git 存储库中运行
git status
、
git branch --track
、
git fetch --all
、
git pull --all
时,映射到带有 Windows 11 和 Git for Windows 版本的 Azure 虚拟机 2.37.3,我收到以下错误:
fatal: detected dubious ownership in repository at '<path>'
'<path>' is owned by:
'S-1-5-18'
but the current user is:
'S-1-5-21-1990399924-2863569968-2306271318-500'
To add an exception for this directory, call:
git config --global --add safe.directory '%(prefix)///<path>'
我测试过:
git config --global --add safe.directory '%(prefix)///<path>'
和
git config --global --add safe.directory '*'
并更改目录和文件权限:
TAKEOWN /F * /R
但是当我在虚拟机的本地文件夹中执行所有这些操作时,一切都运行良好。
我尝试在我的环境中重现相同的结果,但收到如下错误。
解决问题:这个错误通常发生在git会判断当前用户是否是git仓库文件夹的所有者时。如果不是,它将显示如下错误,因为如果该文件夹不属于当前登录的用户,则其他用户可能会在其中添加有害文件。
您可以使用此命令。
git config --global --add safe.directory <path>
由于您已经测试了上述命令,请尝试以下解决方法:
选择git仓库的文件夹。如果此文件夹充满了 git 仓库,您可以选择整个文件夹或选择您的文件 -> 属性 -> 安全性 -> 高级,如下所示:
如果所有者与当前Windows登录帐户不同,请点击更改。
单击“立即查找”并搜索您当前的帐户名,然后单击“确定”。
请通过
halt9k 参考此 SO 线程 以禁用继承。
当我尝试使用 git status 或 git log now 时,不会出现如下错误:
除了(相当神秘的)安全标识符之外,当 Git 目录与 Windows 上的当前用户不匹配时,它现在还会在错误消息中显示用户名和域。
请参阅
提交 f755e09(2024 年 1 月 8 日),作者:Sören Krecker (soerenkrecker-baader
)。
gitster
--合并于 commit b5fb623,2024 年 1 月 19 日)
mingw
:提供有关不安全目录所有权的更多详细信息签署人:Sören Krecker
确认人:Johannes Sixt
如果 Windows 系统上存储库的所有者 sid 和用户 sid 不相等,请在错误消息中添加域/用户名。旧错误消息:
fatal: detected dubious ownership in repository at 'C:/Users/test/source/repos/git' 'C:/Users/test/source/repos/git' is owned by: 'S-1-5-21-571067702-4104414259-3379520149-500' but the current user is: 'S-1-5-21-571067702-4104414259-3379520149-1001' To add an exception for this directory, call: git config --global --add safe.directory C:/Users/test/source/repos/git
新错误消息:
fatal: detected dubious ownership in repository at 'C:/Users/test/source/repos/git' 'C:/Users/test/source/repos/git' is owned by: DESKTOP-L78JVA6/Administrator (S-1-5-21-571067702-4104414259-3379520149-500) but the current user is: DESKTOP-L78JVA6/test (S-1-5-21-571067702-4104414259-3379520149-1001) To add an exception for this directory, call: git config --global --add safe.directory C:/Users/test/source/repos/git