VS 版本更新git安全保护问题的解决

问题:

我可能移动了一个VS C# 项目,然后,发现里面的git版本检测不能用了

正在打开存储库:

X:\Prj_C#\3D

fatal: detected dubious ownership in repository at 'X:/Prj_C#/3DSnapCatch'

'X:/Prj_C#/3D' is owned by:

'S-1-5-32-544'

but the current user is:

'S-1-5-21-900372847-2521881049-1049374117-1001'

To add an exception for this directory, call:

git config --global --add safe.directory 'X:/Prj_C#/3DSnapCatch'

一个做了很久的项目,然后,COPY来,COPY去,后来,客户发了问题要修改,看git版本,VS 里面的git给出了安全的提示。就是不同的用户,你不能访问了。估计是VS登陆的时候,用了不同的用户名,也没注意,总之,VS里面又包了一层。

奇怪的是如果用本地的,git shell,却是可以的:

所以,这个安全目录,感觉就是VS搞的一个附加的安全措施。


解决办法:

1确认安全目录:

确定项目目录下,所有的安全git工作目录:

复制代码
git config --global --get-all safe.directory

比如我的:

复制代码
X:\Prj_C#\3DSnapCatch>git config --global --get-all safe.directory
X:/Prj_C#/3DSnapCatch

如果有多个重复的,那么就不行,会有问题。比如:

复制代码
X:\Prj_C#\3DSnapCatch>git config --global --get-all safe.directory
X:\Prj_C#\3DSnapCatch
X:\Prj_C#\3DSnapCatch

2 移除所有安全目录

如果有重复的,我们需要运行下面的代码:移除所有的安全目录:

复制代码
X:\Prj_C#\3DSnapCatch>git config --global --unset-all safe.directory

【最好的方法,可以上来先移除所有的安全目录,重做一边】

3 重新构建安全目录:

复制代码
X:\Prj_C#\3DSnapCatch>git config --global --add safe.directory "X:/Prj_C#/3DSnapCatch"

4 确认一下:

复制代码
X:\Prj_C#\3DSnapCatch>git config --global --get-all safe.directory
X:/Prj_C#/3DSnapCatch

验证:

相关推荐
深海鱼在掘金6 小时前
Git 完全指南 —— 第3章:理解工作区、暂存区、版本库三个核心
git
江华森7 小时前
Git 基础筑基:从原理到团队协作的全栈实战
git
JakeJiang11 小时前
Git 必备命令指南:从日常高频到项目开发实战
git
叫我少年1 天前
Windows 中安装 git
git
深海鱼在掘金7 天前
Git 完全指南 —— 第1章:Git 概览与版本控制演进
git
noravinsc7 天前
关于Git Flow
git
蜜獾云7 天前
在Git中配置用户名和密码
git
scx_link7 天前
通过git bash在本地创建分支,并推送到远程仓库中
开发语言·git·bash
南大白7 天前
IntelliJ IDEA 运行时的 JVM 本地内存溢出崩溃
git
码农小旋风8 天前
Claude Code 基础用法大全:对话、分析、修改、测试、Git 和工作流
人工智能·git·chatgpt·claude