fatal: detected dubious ownership in repository git报错解决

环境

win10,git

原因

由于win10重装系统后,文件夹所有者变了,导致git pull等都出现了该问题

fatal: detected dubious ownership in repository at 'E:/xxxx'
'E:/xxxx' is owned by:
        'S-1-5-21-2006691667-4270939040-3929086740-1001'
but the current user is:
        'S-1-5-21-3445211471-1722826824-3856863527-1001'
To add an exception for this directory, call:
        git config --global --add safe.directory E:/xxxx

解决方案

变更文件夹权限

在这里插入图片描述
在这里插入图片描述

设置git安全目录

  • Git只允许您访问自己拥有的存储库,默认情况下,也就是运行Git的用户
  • 默认情况下,Git甚至会拒绝解析别人拥有的存储库的Git配置,更不用说运行它的钩子了,这个配置设置允许用户指定例外情况
  • safe.directory 这些配置项指定了git跟踪的目录,即使这些目录不是当前用户所拥有的,它们也被认为是安全的
#设置E:/xxx目录为安全目录
git config --global --add safe.directory E:/xxx

#目录设置为字符串*。这将允许所有存储库被视为它们的目录被列在保险箱中。
git config --global --add safe.directory *

git config safe.directory 官网说明

safe.directory
These config entries specify Git-tracked directories that are considered safe even if they are owned by someone other than the current user. By default, Git will refuse to even parse a Git config of a repository owned by someone else, let alone run its hooks, and this config setting allows users to specify exceptions, e.g. for intentionally shared repositories (see the --shared option in git-init[1]).

This is a multi-valued setting, i.e. you can add more than one directory via git config --add. To reset the list of safe directories (e.g. to override any such directories specified in the system config), add a safe.directory entry with an empty value.

This config setting is only respected in protected configuration (see SCOPES). This prevents the untrusted repository from tampering with this value.

The value of this setting is interpolated, i.e. ~/ expands to a path relative to the home directory and %(prefix)/ expands to a path relative to Git’s (runtime) prefix.

To completely opt-out of this security check, set safe.directory to the string . This will allow all repositories to be treated as if their directory was listed in the safe.directory list. If safe.directory= is set in system config and you want to re-enable this protection, then initialize your list with an empty value before listing the repositories that you deem safe.

As explained, Git only allows you to access repositories owned by yourself, i.e. the user who is running Git, by default. When Git is running as root in a non Windows platform that provides sudo, however, git checks the SUDO_UID environment variable that sudo creates and will allow access to the uid recorded as its value in addition to the id from root. This is to make it easy to perform a common sequence during installation “make && sudo make install”. A git process running under sudo runs as root but the sudo command exports the environment variable to record which id the original user has. If that is not what you would prefer and want git to only trust repositories that are owned by root instead, then you can remove the SUDO_UID variable from root’s environment before invoking git.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值