小工具知识网

当前位置: 首页 > 行业知识 > git fatal: detected dubious ownership in repository at ‘xxx‘ 彻底解决方法

行业知识

git fatal: detected dubious ownership in repository at ‘xxx‘ 彻底解决方法

2026-11-12 23:18:43 来源:互联网转载

前言

  • 在 windows 重置后, git 仓库无法正常使用 git 的所有 命令,运行任何 git 命令,都会提示如下:
    $ git logfatal: detected dubious ownership in repository at 'D:/rk/rk3568/nanopi/uboot-rockchip''D:/rk/rk3568/nanopi/uboot-rockchip' is owned by:        'S-1-5-21-1045045257-1974506225-3199486363-1001'but the current user is:        'S-1-5-21-3027747537-4188049438-3617488890-1001'To add an exception for this directory, call:        git config --global --add safe.directory D:/rk/rk3568/nanopi/uboot-rockchip
    • 这个问题主要原因是用户变更引起的,但是 如果仓库很大,把这个 git 仓库变更为当前用户就会很耗时间,还不如重新拉取仓库来的方便

    • 被这个【问题】困扰了一段时间,这次系统重置,又遇到了这个问题,难道 git 设计就这么 low 吗?有没有更快速简单的方法,彻底解决 【用户目录变更】造成 所有 git 仓库 无法使用 git 命令这个问题?

      彻底解决方法

      • 问题归根到底,就是 safe.directory 问题。安全目录,这个能关闭吗?

      • 解决方法: 一条 git 配置 git config --global safe.directory '*'

      • 效果类似于在 C:\Users\admin\.gitconfig windows【用户目录】下 的 git 全局配置中,增加如下的属性

        [safe]directory = *
        • 【So easy】,并且很有效!

          运行

          • 这个是在全局的 git 配置文件中,增加了一条 [safe] 的配置,设置后,问题解决,所有的目录,不再需要 safe.directory 检查,也不需要担心 变更系统账号,造成 git 仓库无法使用 git 命令了

          • 这个设置,应该是让所有的目录有效,也就是 * 号的作用,而不是关闭 safe.directory,不过这个设置已经非常简单。

上一篇:Spring Boot 项目集成camunda流程引擎

下一篇:传奇服务器时间不准怎么调?