【问题标题】:Git add errors: Could not open directory: Permission DeniedGit添加错误:无法打开目录:权限被拒绝
【发布时间】:2018-12-26 12:20:33
【问题描述】:

我使用的是 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

【问题讨论】:

  • 您当前的工作目录是什么? C:\Users\<username>?恐怕你在错误的路径上使用Git命令很长时间了......
  • @GenoChen 一定是这样的%UserProfile%
  • @iBug 同意。这些文件夹很可能是 Windows 下的主目录。
  • @GenoChen 非常感谢您的回复 /c/Users/Mateo
  • @MateoChiyangi 就是这样。为什么要在这条路径上执行 Git 命令...?

标签: windows git git-bash


【解决方案1】:

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

【讨论】:

  • “尝试确保所有文件都已保存,并关闭所有打开的 IDE。” - 这有帮助。我在文本比较工具中打开了一个文件。谢谢!
【解决方案2】:

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

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

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

默认的当前工作目录称为主目录,在 *nix 中为~ 或主要是/home/&lt;user&gt;/root,在Windows 中为C:\Users\&lt;user&gt;(非管理员)或C:\Windows\System32(管理员)>在 Windows C:\Documents and Settings\<user>。

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

【讨论】:

  • 非常感谢您的详细回复。如何确保我在正确的目录中?
猜你喜欢
  • 2021-06-12
  • 2015-11-29
  • 2018-10-01
  • 2017-01-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-23
相关资源
最近更新 更多