Win10跨系统Git权限报错:映射目录不安全问题求助
问题背景
本地Windows 10系统「My」的C:\cap2office是Git仓库,远程Windows 10系统「Remote」通过RDP将本地C盘映射为S盘,可通过S:\cap2office访问仓库,两台系统用户名不同。
在远程系统执行git status时,出现所有权不匹配错误:
warning: '//tsclient/C/cap2office' is on a file system that does not record ownership
fatal: unsafe repository ('//tsclient/C/cap2office' is owned by someone else)
To add an exception for this directory, call:
git config --global --add safe.directory '%(prefix)///tsclient/C/cap2office'
尝试添加S:/cap2office或//tsclient/C/cap2office到全局safe.directory均无效,同时找不到.gitconfig文件。
解决方案
1. %(prefix)的正确用法
%(prefix)是Git内置变量,无需手动设置,直接执行Git提示的完整命令即可:
git config --global --add safe.directory "%(prefix)///tsclient/C/cap2office"
该变量会自动适配Windows路径规则,确保Git正确识别RDP映射的网络路径。
2. 磁盘映射导致配置无效的原因
远程系统中的S:\cap2office是映射盘符,但Git实际识别的是底层网络路径//tsclient/C/cap2office,因此添加映射路径无法被Git匹配,必须使用报错中显示的完整网络路径(配合%(prefix)变量)才能生效。
3. .gitconfig文件的位置
Windows上Git全局配置文件的位置分两种情况:
- 系统级安装的Git:全局配置文件通常在
C:\Program Files\Git\etc\gitconfig - 用户级配置:默认在
C:\Users\<远程系统用户名>\.gitconfig,若找不到,需在文件资源管理器中开启「显示隐藏的项目」选项
也可通过命令直接查看全局配置文件路径:
git config --global --show-origin
内容的提问来源于stack exchange,提问作者Paul Kinzelman

