Git 添加错误:无法打开目录:权限被拒绝

Mat*_*ngi 2 windows git git-bash

我使用的是 Windows 10。当我输入命令“git add”时。在我的 Git Bash 中,我不断收到此消息,如下所示:

warning: could not open directory 'AppData/Local/Application Data/': Permission denied
warning: could not open directory 'AppData/Local/ElevatedDiagnostics/': Permission denied
warning: could not open directory 'AppData/Local/History/': Permission denied
warning: could not open directory 'AppData/Local/Microsoft/Windows/INetCache/Content.IE5/': Permission denied
warning: could not open directory 'AppData/Local/Microsoft/Windows/Temporary Internet Files/': Permission denied
warning: could not open directory 'AppData/Local/Temporary Internet Files/': Permission denied
warning: could not open directory 'Application Data/': Permission denied
warning: could not open directory 'Cookies/': Permission denied
warning: could not open directory 'Documents/My Music/': Permission denied
warning: could not open directory 'Documents/My Pictures/': Permission denied
warning: could not open directory 'Documents/My Videos/': Permission denied
warning: could not open directory 'Local Settings/': Permission denied
warning: could not open directory 'My Documents/': Permission denied
warning: could not open directory 'NetHood/': Permission denied
warning: could not open directory 'PrintHood/': Permission denied
warning: could not open directory 'Recent/': Permission denied
warning: could not open directory 'SendTo/': Permission denied
warning: could not open directory 'Start Menu/': Permission denied
warning: could not open directory 'Templates/': Permission denied
Run Code Online (Sandbox Code Playgroud)

dan*_*man 9

如果其他人在搜索此错误时来到这里,并且他们肯定已经在正确的路径上,则此问题可能是由工作目录中未保存的文件引起的 - 尝试确保所有文件都已保存,并关闭任何打开的 IDE

  • “尝试确保所有文件均已保存,并关闭所有打开的 IDE。” - 这有帮助。我在文本比较工具中打开了一个文件。谢谢你! (2认同)

Gen*_*hen 2

您正在意外的目录上运行 Git 子命令。

大多数 Git 子命令都是路径相关的。大多数情况下,这些子命令将当前工作目录视为 Git 根目录,并在 Git 根目录执行 Git 操作。

对于常规使用,我们将代码项目的根目录视为 Git 根目录。多个代码项目会产生多个文件夹和多个相应的 Git 根。使用当前工作目录来指定它们。

默认的当前工作目录称为主目录,它是~或大部分/home/<user>/root在*nix中,或者在Windows > 7或Windows <= XP中C:\Users\<user>是(非管理员)或(管理员) 。C:\Windows\System32C:\Documents and Settings\<user>

如果您没有指定当前工作目录(使用命令cd),则所有 Git 操作都会操作您的主目录。在某些情况下这可能是有害的。小灾难就像你遇到的那样,大灾难可能是你不小心将你的私人文件上传到 GitHub 或你意识到这一点后的类似情况。