Linux 无法将文件添加到 git 存储库,但可以更改/提交
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7864872/
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 file to git repository but can change / commit
提问by cnd
here is error :
这是错误:
git add .emacs
error: insufficient permission for adding an object to repository database .git/objects
error: .emacs: failed to insert into database
error: unable to index file .emacs
fatal: adding files failed
how can I fix it ? what's wrong with it ?
我该如何解决?它出什么问题了 ?
采纳答案by Amber
error: insufficient permission for adding an object to repository database .git/objects
That is your problem. For some reason or another, Git is having trouble writing to .git/objects
- typically this means it is owned by another user and doesn't have the proper permissions.
那是你的问题。出于某种原因,Git 无法写入.git/objects
- 通常这意味着它由另一个用户拥有并且没有适当的权限。
Try seeing what permissions the folder currently has by running ls -l .git/objects
. Then, you can chmod
or chown
(or both) as necessary.
尝试通过运行查看文件夹当前具有的权限ls -l .git/objects
。然后,您可以根据需要chmod
或chown
(或两者)。
回答by Eric Jones
I hadn't changed any permissions on my files, but I had the same error message and fixed it by changing ownership on the git directory (chown -R user:group .git).
我没有更改我的文件的任何权限,但我有相同的错误消息并通过更改 git 目录(chown -R user:group .git)的所有权来修复它。
回答by Josiah
This can be caused by accidentally sudo'ing a git commit. You don't intentionally change permissions and sudo will work in most configs, but the next time it is tried without sudo you'll have issues.
这可能是由于意外 sudo'ing git commit 造成的。您不会有意更改权限并且 sudo 将在大多数配置中工作,但是下次在没有 sudo 的情况下尝试时,您会遇到问题。
Simply revert the permissions on the .git directory to what they would have been previously using a command like this.
只需使用这样的命令将 .git 目录的权限恢复到他们以前的权限。
sudo chown -R user:group .git