无法将文件添加到 git 存储库,但可以更改/提交

发布于 2024-12-11 10:15:22 字数 274 浏览 0 评论 0原文

这是错误:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

很酷不放纵 2024-12-18 10:15:22
error: insufficient permission for adding an object to repository database .git/objects

那是你的问题。由于某种原因,Git 在写入 .git/objects 时遇到问题 - 通常这意味着它由另一个用户拥有,并且没有适当的权限。

尝试通过运行 ls -l .git/objects 来查看该文件夹当前拥有哪些权限。然后,您可以根据需要 chmodchown(或两者)。

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.

Try seeing what permissions the folder currently has by running ls -l .git/objects. Then, you can chmod or chown (or both) as necessary.

信仰 2024-12-18 10:15:22

我没有更改文件的任何权限,但我有相同的错误消息,并通过更改 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).

天涯离梦残月幽梦 2024-12-18 10:15:22

这可能是由于意外 sudo 执行 git 提交造成的。您不会故意更改权限,并且 sudo 在大多数配置中都可以工作,但下次在不使用 sudo 的情况下尝试时,您会遇到问题。

只需使用这样的命令将 .git 目录的权限恢复到之前的权限即可。

sudo chown -R user:group .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.

sudo chown -R user:group .git
凉薄对峙 2024-12-18 10:15:22

请注意,对于最新(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 日)

commit:修复权限错误中的重复回归输出

签字人:Ævar Arnfjörð Bjarmason

修复了无法写入 .git/objects 时发出的错误输出中的回归问题。
9c4d6c0之前(“cache-tree:写入更新的缓存-提交后的树”,2014-07-13,Git v2.2.0-rc0 -- 合并)我们只会发出一个“权限不足” “错误,现在我们将再次这样做。

原因相当简单,我们有WRITE_TREE_SILENT用于想要静默准备索引、安静任何权限等的用例。
错误输出。
然后,当我们尝试更新该(可能已损坏)索引时,我们将再次遇到相同的错误。

但是 9c4d6c0 缓存树 API 和对象存储之间的差距询问方面并未结束write_object_file() 保持沉默。

post-9c4d6c0 第一次调用是 prepare_index() ,之后我们会调用prepare_to_commit()
我们只想要后者的详细错误输出。

因此,让我们添加并使用该设施以及相应的 HASH_SILENT 标志,其唯一用户是 cache-tree.cupdate_one(),如果其 "WRITE_TREE_SILENT" 标志为设置。

因此,除了修复问题所需的 chown 之外,如果您两次看到错误消息,也不要感到惊讶。


您在合并时也有类似的错误(确实涉及 add

在只读存储库中,“git合并树(man) 尝试提出一个合并结果树对象,但它失败了(这不是错误的)并导致了段错误(这很糟糕),该错误已被纠正git 2.39 (2022 年第四季度)。

请参阅 提交 92481d1提交 0b55d93(2022 年 9 月 28 日),作者:约翰内斯·辛德林 (dscho)
(由 Junio C Hamano -- gitster -- 合并于 提交 19118cb,2022 年 10 月 10 日)

merge-ort:失败时提前返回写一个 blob

审阅者:Elijah Newren
签字人:Johannes Schindelin

在之前的提交中,我们修复了无法写入树对象时的分段错误。

但是,在写入树对象之前,merge-ort 想要写出一个 blob 对象(除非合并导致数据库中已存在 blob)。
这也可能会失败,但到目前为止我们忽略了写入失败。

让我们密切关注,如果无法写入 blob,请尽早出错。
这减少了 t4301.25 的错误输出(“merge-ort 在只读存储库中正常失败”):

错误:没有足够的权限将对象添加到存储库数据库./objects
错误:错误:无法将数字添加到数据库
错误:没有足够的权限将对象添加到存储库数据库./objects
错误:错误:无法将问候语添加到数据库
错误:没有足够的权限将对象添加到存储库数据库./objects
致命:合并失败

至:

错误:没有足够的权限将对象添加到存储库数据库./objects
错误:错误:无法将数字添加到数据库
致命:合并失败

不仅仅是表面上的改变:尽管人们可能会假设在写入新树对象时该操作无论如何都会失败(并且相应的树对象 如果它包含一个新的 blob,那么它就是新的),但事实并非如此:

正如 Elijah Newren 指出的,当 Git 之前被允许通过 sudo 调用添加松散对象时,很可能无法写入 blob 对象(因为相应的 . git/objects/??/ 目录可能由 root 所有),但树对象可以写入(因为相应的对象目录由当前用户所有)。

这会导致存储库损坏,因为它缺少 blob 对象,通过此补丁我们可以防止这种情况发生。

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)

commit: fix duplication regression in permission error output

Signed-off-by: Ævar Arnfjörð Bjarmason

Fix a regression in the error output emitted when .git/objects can't be written to.
Before 9c4d6c0 ("cache-tree: Write updated cache-tree after commit", 2014-07-13, Git v2.2.0-rc0 -- merge) we'd emit only one "insufficient permission" error, now we'll do so again.

The cause is rather straightforward, we've got WRITE_TREE_SILENT for the use-case of wanting to prepare an index silently, quieting any permission etc.
error output.
Then when we attempt to update to that (possibly broken) index we'll run into the same errors again.

But with 9c4d6c0 the gap between the cache-tree API and the object store wasn't closed in terms of asking write_object_file() to be silent.
I.e.
post-9c4d6c0 the first call is to prepare_index(), and after that we'll call prepare_to_commit().
We only want verbose error output from the latter.

So let's add and use that facility with a corresponding HASH_SILENT flag, its only user is cache-tree.c's update_one(), which will set it if its "WRITE_TREE_SILENT" flag is set.

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)

merge-ort: return early when failing to write a blob

Reviewed-by: Elijah Newren
Signed-off-by: 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 by root) 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文