Git add errors: Could not open directory: Permission Denied

孤街醉人 提交于 2019-11-28 06:54:39

问题


I am using windows 10. When I type the command "git add ." in my Git Bash I keeping getting this message as shown below:

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

回答1:


You are running Git subcommand on a unexpected directory.

Most of Git subcommand are path-dependent. In most cases these subcommand treats the current working directory as Git root, and do Git operations inside Git root.

For regular usage, we treat the root directory for code project as Git root. Multiple code project results in multiple folder, and multiple corresponding Git roots. Use current working directory to specify them.

The default current working directory is called Home directory, which is ~ or mostly /home/<user> or /root in *nix, or C:\Users\<user> (non-Administrator) or C:\Windows\System32 (Administrator) in Windows > 7 or C:\Documents and Settings\<user> in Windows <= XP.

If you didn't specify current working directory (with command cd), all the Git operations are operating your home directory. This can be harmful under some situations. Small disaster is just like what you met, big disaster can be something like you accidently uploaded your private file in GitHub or something equivalent after you realized that.



来源:https://stackoverflow.com/questions/53932041/git-add-errors-could-not-open-directory-permission-denied

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!