这里出现了错误:
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
我该如何修复它?它出了什么问题?
这里出现了错误:
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
error: insufficient permission for adding an object to repository database .git/objects
这就是你的问题所在。由于某种原因,Git无法写入.git/objects - 通常意味着它由另一个用户拥有且没有正确的权限。
尝试通过运行ls -l .git/objects
来查看文件夹当前的权限。然后,您可以根据需要使用chmod
或chown
(或两者都)进行更改。
我没有改变文件的权限,但是出现了相同的错误信息,通过更改git目录的所有权(chown -R user:group .git)解决了问题。
sudo chown -R user:group .git
git commit
"(man)会给出重复的错误消息,这在Git 2.34(2021年第四季度)中已得到修正。
查看提交 4ef91a2,提交 119b26d(2021年10月12日)由Ævar Arnfjörð Bjarmason (avar
)提交。
(由Junio C Hamano -- gitster
--合并于提交 2c428e4,2021年10月25日)
commit
:修复权限错误输出中的重复回归问题签名作者:Ævar Arnfjörð Bjarmason
修复了一个回归问题,即在无法写入.git/objects
时发出的错误输出。cache-tree
: Write updated cache-tree after commit", 2014-07-13, Git v2.2.0-rc0 -- merge)之前,我们只会发出一个"权限不足"的错误,现在我们又会这样做了。WRITE_TREE_SILENT
用例,想要静默地准备索引,消除任何权限等错误输出。write_object_file()
保持沉默方面没有被消除。prepare_index()
,之后我们将调用prepare_to_commit()
。HASH_SILENT
标志的设施,它的唯一用户是cache-tree.c
的update_one()
,如果设置了其"WRITE_TREE_SILENT"
标志,则会将其设置。
所以除了需要使用chown
来解决问题之外,如果你看到错误信息两次,也不要感到惊讶。
在合并操作中,你也遇到了类似的错误(涉及到add
)
在只读仓库中,"git merge-tree
"(man) 试图生成一个合并结果树对象,但失败了(这是正常的),导致了段错误(这是不好的),这个问题已经在 Git 2.39(2022年第四季度)中得到了修复。
请查看92481d1提交,0b55d93提交(2022年9月28日)来自Johannes Schindelin (dscho
)。
(由Junio C Hamano -- gitster
--在19118cb提交中合并,于2022年10月10日)
merge-ort
:在写入blob失败时提前返回经过Elijah Newren审核
Johannes Schindelin签署
In the previous commit, we fixed a segmentation fault when a tree object could not be written.
However, before the tree object is written,
merge-ort
wants to write out a blob object (except in cases where the merge results in a blob that already exists in the database).
And this can fail, too, but we ignore that write failure so far.Let's pay close attention and error out early if the blob could not be written.
This reduces the error output of t4301.25 ("merge-ort fails gracefully in a read-only repository") from:
error: insufficient permission for adding an object to repository database ./objects error: error: Unable to add numbers to database error: insufficient permission for adding an object to repository database ./objects error: error: Unable to add greeting to database error: insufficient permission for adding an object to repository database ./objects fatal: failure to merge
to:
error: insufficient permission for adding an object to repository database ./objects error: error: Unable to add numbers to database fatal: failure to merge
This is not just a cosmetic change: Even though one might assume that the operation would have failed anyway at the point when the new tree object is written (and the corresponding tree object will be new if it contains a blob that is new), but that is not so:
As pointed out by Elijah Newren, when Git has previously been allowed to add loose objects via
sudo
calls, it is very possible that the blob object cannot be written (because the corresponding.git/objects/??/
directory may be owned byroot
) but the tree object can be written (because the corresponding objects directory is owned by the current user).This would result in a corrupt repository because it is missing the blob object, and with this here patch we prevent that.