无法将文件添加到 git 存储库,但可以更改/提交
这是错误:
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
我该如何修复它?有什么问题吗?
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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
那是你的问题。由于某种原因,Git 在写入
.git/objects
时遇到问题 - 通常这意味着它由另一个用户拥有,并且没有适当的权限。尝试通过运行 ls -l .git/objects 来查看该文件夹当前拥有哪些权限。然后,您可以根据需要
chmod
或chown
(或两者)。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.Try seeing what permissions the folder currently has by running
ls -l .git/objects
. Then, you canchmod
orchown
(or both) as necessary.我没有更改文件的任何权限,但我有相同的错误消息,并通过更改 git 目录的所有权(chown -R user:group .git)来修复它。
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).
这可能是由于意外 sudo 执行 git 提交造成的。您不会故意更改权限,并且 sudo 在大多数配置中都可以工作,但下次在不使用 sudo 的情况下尝试时,您会遇到问题。
只需使用这样的命令将 .git 目录的权限恢复到之前的权限即可。
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.
Simply revert the permissions on the .git directory to what they would have been previously using a command like this.
请注意,对于最新(2014+)版本的 Git,“
git 提交
"(man) 当对象时给出重复错误消息store 不可写,已使用 Git 2.34(2021 年第 4 季度)进行更正。请参阅提交4ef91a2,提交 119b26d(2021 年 10 月 12 日),作者:Ævar Arnfjörð Bjarmason (
avar
)。(由 Junio C Hamano --
gitster
-- 合并于 提交 2c428e4,2021 年 10 月 25 日)因此,除了修复问题所需的
chown
之外,如果您两次看到错误消息,也不要感到惊讶。您在合并时也有类似的错误(确实涉及
add
)在只读存储库中,“
git合并树
“(man) 尝试提出一个合并结果树对象,但它失败了(这不是错误的)并导致了段错误(这很糟糕),该错误已被纠正git 2.39 (2022 年第四季度)。请参阅 提交 92481d1,提交 0b55d93(2022 年 9 月 28 日),作者:约翰内斯·辛德林 (
dscho
)。(由 Junio C Hamano --
gitster
-- 合并于 提交 19118cb,2022 年 10 月 10 日)Note that with more recent (2014+) versions of Git, "
git commit
"(man) gave duplicated error message when the object store was unwritable, which has been corrected with Git 2.34 (Q4 2021).See commit 4ef91a2, commit 119b26d (12 Oct 2021) by Ævar Arnfjörð Bjarmason (
avar
).(Merged by Junio C Hamano --
gitster
-- in commit 2c428e4, 25 Oct 2021)So in addition of the
chown
you need for fixing the issue, don't be surprise if you see the error message twice.You also have a similar error on merges (which does involve
add
)In read-only repositories, "
git merge-tree
"(man) tried to come up with a merge result tree object, which it failed (which is not wrong) and led to a segfault (which is bad), which has been corrected with Git 2.39 (Q4 2022).See commit 92481d1, commit 0b55d93 (28 Sep 2022) by Johannes Schindelin (
dscho
).(Merged by Junio C Hamano --
gitster
-- in commit 19118cb, 10 Oct 2022)