前言
- 在 windows 重置后, git 仓库无法正常使用 git 的所有 命令,提示
$ git log
fatal: 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 设计就这么 low 吗?有没有更快速简单的方法,彻底解决 【用户目录变更】造成 git 仓库 无法使用 git 命令这个问题?
彻底解决方法
-
问题归根到底,就是 safe.directory 问题。
-
解决方法: 一条配置
git config --global safe.directory '*'
-
类似于在
C:\Users\admin\.gitconfig
git 全局配置中,增加如下的属性
[safe]
directory = *
效果
- 这个是在全局的 git 配置文件中,增加了一条 [safe] 的配置,设置后,问题解决,所有的目录,不再需要
safe.directory
检查,也不需要担心 变更系统账号,造成 git 仓库无法使用 git 命令了