Cannot check the working tree for unmerged files because of an error. detected dubious ownership in
Cannot check the working tree for unmerged files because of an error. detected dubious ownership in repository at 'D:/work' 'D:/work' is owned by: (inconvertible) (S-1-5-21-2113155594-4284400611-412257257-1001) but the current user is: Administrator (S-1-5-2) To add an exception for this directory, call: git config --global --add safe.directory D:/work
这个报错是 Git 安全机制导致的。它检测到当前用户(Administrator)和仓库目录的原始所有者(另一个 SID 用户)不一致,因此 拒绝访问工作区。
🔍 原因
Git 2.35 之后新增了安全检查机制:
当仓库目录的 文件所有者(Owner)与当前登录用户不一致 时,Git 认为该仓库“可疑”(dubious),防止潜在的安全风险(例如多用户系统上恶意仓库)。
✅ 解决方法
方法 1:给 Git 添加安全目录白名单(推荐)
执行下面这条命令:
git config --global --add safe.directory D:/work
然后再重新执行你原来的命令(如 git status 或 git merge)。
✅ 作用:告诉 Git 这个目录是安全的,即使用户不匹配也可以操作。
方法 2:如果你有多个类似目录
你可以批量允许当前整个工作区路径:
git config --global --add safe.directory D:/work*
或者直接允许所有目录(不建议):
git config --global --add safe.directory '*'
⚠️ 这会关闭 Git 的目录安全校验,对安全要求高的环境请慎用。
方法 3:如果这是因为复制/迁移仓库造成的
比如:
-
从另一个用户账户复制来的仓库
-
从压缩包中解压的旧仓库
你也可以用管理员权限执行一次:
takeown /F D:\work /R /D Y
或在 PowerShell 中执行:
icacls "D:\work" /setowner "Administrator" /T
让当前用户成为该目录的真正所有者,然后 Git 就不会再提示“dubious ownership”。
💡 建议顺序
-
先试
git config --global --add safe.directory ... -
如果还有提示,再执行 修改目录所有权。
-
最后确认:
git status正常显示即可。
更多推荐



所有评论(0)