【无标题】

发布于:2025-04-16 ⋅ 阅读:(15) ⋅ 点赞:(0)

$ git remote add https://github.com/Sxwang0320/SARDInn.git
fatal: detected dubious ownership in repository at ‘W:/coder/SARDInn’
‘W:/coder/SARDInn’ is on a file system that does not record ownership
To add an exception for this directory, call:

    git config --global --add safe.directory W:/coder/SARDInn

解决方法:
你可以按照以下步骤解决该问题:


1. 添加安全目录配置

Git 检测到仓库所在的文件系统(如网络驱动器或外置硬盘)不支持所有权验证,需手动将其标记为安全:

git config --global --add safe.directory W

此命令将允许 Git 信任该路径下的仓库,绕过所有权检查。


2. 修正 git remote add 命令语法

你使用的命令缺少远程仓库名称(如 origin),正确格式应为:

git remote add origin https://github.com/fg/SARDInn.git
  • origin 是远程仓库的默认名称(可自定义)。
  • 确认 URL 正确(你的仓库地址应为 https://github.com/d0/SARDInn.git)。

3. 验证远程仓库是否添加成功

执行以下命令检查远程仓库配置:

git remote -v

正常应显示:

origin  https://github.com/fsf/SARDInn.git (fetch)
origin  https://github.com/fwfew/SARDInn.git (push)

4. 推送代码(如果尚未推送)

若需将本地代码推送到 GitHub,执行:

git push -u origin main
# 或根据分支名称调整,如 master

补充说明

  1. 文件系统问题

    • 该错误常见于外置硬盘、网络驱动器或 FAT32/exFAT 格式的磁盘,因它们不记录文件所有权。
    • 若长期使用此类存储,建议在 safe.directory 中配置路径。
  2. 安全性提示

    • 添加 safe.directory 仅在你完全信任该目录时使用,避免恶意仓库的风险。
  3. 检查 Git 版本

    • 该功能在 Git 2.35.2+ 引入,可升级至最新版本:
      git --version
      

完成上述步骤后,即可正常操作 Git 仓库。如


网站公告

今日签到

点亮在社区的每一天
去签到