由于权限,无法将所有文件添加到 git
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/356323/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
can't add all files to git due to permissions
提问by singpolyma
I want to add all the files in the current directory to git:
我想把当前目录下的所有文件都添加到git中:
git add .
error: open(".mysql_history"): Permission denied
fatal: unable to index file .mysql_history
That's fine. That file happens to be in this directory and owned by root. I want to add all otherfiles. Is there a way to do that without having to manually add each file by hand?
没关系。该文件恰好在此目录中并由 root 拥有。我想添加所有其他文件。有没有办法做到这一点而不必手动添加每个文件?
I know that I could add the file to exclude or .gitignore, but I'd like to have it just ignore things based on permissions (there's a good chance other files like this will end up in the directory, and adding them to .gitignore all the time is a pain).
我知道我可以将文件添加到 exclude 或 .gitignore,但我想让它忽略基于权限的东西(很有可能像这样的其他文件最终会出现在目录中,并将它们添加到 .gitignore所有的时间都是一种痛苦)。
回答by matli
Use git add --ignore-errors .
用 git add --ignore-errors .
This will still give an error for the unreadable file(s), but not a fatal one. The other files will be added.
这仍然会为不可读的文件提供错误,但不是致命的。将添加其他文件。
回答by Tsal Giorgos
Closing your IDE or whatever that uses the relative files you want to upload solved my problem
关闭您的 IDE 或使用您要上传的相关文件的任何内容解决了我的问题
回答by mwilliams
Would it help if you added that file to your .gitignore file? So all other files would be versioned and that file would get ignored (unless you need it).
如果您将该文件添加到 .gitignore 文件中会有所帮助吗?因此,所有其他文件都将被版本化,并且该文件将被忽略(除非您需要它)。
回答by Alexx Roche
sudo chown $(whoami): .git/objects/ -R; git add --ignore-errors .
fixed it for me. The first half fixed ownership, (someone checked-in as root, naughty) and the second half makes errors non-fatal. The second half on its own helped me track down which directory was owned by root.
为我修好了。前半部分固定所有权(有人以 root 身份签入,顽皮),后半部分犯了非致命错误。后半部分本身帮助我追踪 root 拥有哪个目录。
回答by Benjamin Lucidarme
As @Dhanuka777 pointed in comments, if you are using Visual Studio or Unity, you have to shutdown all Visual Studio and Unity instances before git add .
正如@Dhanuka777 在评论中指出的那样,如果您使用的是 Visual Studio 或 Unity,则必须在 git add 之前关闭所有 Visual Studio 和 Unity 实例。
回答by mipadi
Just exclude the file. You can add .mysql_history
to a .gitignore
file, or add it to .git/info/exclude
.
只需排除该文件。您可以添加.mysql_history
到.gitignore
文件,或将其添加到.git/info/exclude
.
Adding an entry to .gitignore
will propagate the setting with the repo (since .gitignore
is stored with the repo); adding it to .git/info/exclude
makes it "personal" because this file is notpropagated with the repo. Either way, .mysql_history
will be ignored by git-add
and friends.
添加一个条目 to.gitignore
将通过 repo 传播设置(因为.gitignore
与 repo 一起存储);添加它.git/info/exclude
使其成为“个人”,因为此文件不随 repo 传播。无论哪种方式,.mysql_history
都会被git-add
和朋友忽视。
You can read more about ignoring files with Git on this man page.
您可以在此手册页上阅读有关使用 Git 忽略文件的更多信息。
回答by InsParbo
I was using @matli 's solution but still having troubles sometimes. I ended up using
我正在使用 @matli 的解决方案,但有时仍然遇到麻烦。我最终使用
git add --ignore-errors --force .
git add --ignore-errors --force .
回答by sai
Closed all instances of visual studio worked for me
关闭了所有对我来说有效的视觉工作室实例
回答by shaza
Please Specify file name you want to add; example:
请指定您要添加的文件名;例子:
git add index.html
I hope this helps you also
我希望这也能帮助你
回答by nachoiz
Check if there is some task/process related to those files running in background.
检查是否有一些与后台运行的文件相关的任务/进程。
I realised trying to empty my Temp folder. When a file cannot be erased, Windows informs you which is the process related to. Killing that process solved me the problem.
我意识到试图清空我的 Temp 文件夹。当无法擦除文件时,Windows 会通知您与哪个进程相关。杀死那个进程解决了我的问题。
That's why finishing the IDE or restarting the system usually works.
这就是为什么完成 IDE 或重新启动系统通常有效的原因。