What does git mean by, “unable to migrate objects to permanent storage”?

之前偶尔发现提交代码会出现被拒绝情况,一开始以为可以用 gc 来解决问题,或者通过创建创建新分支或者重新提交代码来规避,然后发现被拒绝概率越来越高。遇到问题解决问题。

各种 google、百度加 stackOverflow,终于在 stackOverflow 上面看到一种解释,主要针对较高版本 git 和 gitlab,本地在提交 commit 的时候需要先提交到 tmp_objdir_migrate 然后再提交到仓库里面

    /*
     * Now we'll start writing out refs, which means the objects need
     * to be in their final positions so that other processes can see them.
     */
    if (tmp_objdir_migrate(tmp_objdir) < 0) {
        for (cmd = commands; cmd; cmd = cmd->next) {
            if (!cmd->error_string)
                cmd->error_string = "unable to migrate objects to permanent storage";
        }
        return;
    }
tmp_objdir = NULL;

Quarantine Environment

When receive-pack takes in objects, they are placed into a temporary “quarantine” directory within the $GIT_DIR/objects directory and migrated into the main object store only after the pre-receive hook has completed. If the push fails before then, the temporary directory is removed entirely.

This has a few user-visible effects and caveats:

  1. Pushes which fail due to problems with the incoming pack, missing objects, or due to the pre-receive hook will not leave any on-disk data. This is usually helpful to prevent repeated failed pushes from filling up your disk, but can make debugging more challenging.
  2. Any objects created by the pre-receive hook will be created in the quarantine directory (and migrated only if it succeeds).
  3. The pre-receive hook MUST NOT update any refs to point to quarantined objects. Other programs accessing the repository will not be able to see the objects (and if the pre-receive hook fails, those refs would become corrupted).

根据被拒绝的 log:./objects/c5/77e0eb9f2a855232d6b26e957ad71c431fdbaa: Permission denied 我们知道这个目录文件夹出问题了,于是我们想去找到服务器项目所在的路径,发现里面空空如也,一般项目路径下面会有 xx.git 代表这个仓库所在文件夹,然而没有,貌似只有 @hash 里面有很多不规则命名的文件夹。

一开始以为 git 文件夹被谁意外删掉了,然而 gitlab 网页加载正常,完全没有被删掉的异常表现。之前修复问题的时候弄坏过 git 项目,弄坏了的 git 项目,网页是会加载失败。

于是去看看 gitlab 相关知识,看了相关文档,原来项目路径都被放到 @hash 这个文件夹下面了,要查到项目具体路径,提供了两种方法,一种是通过 gitlab 网页客户端的 admin 后台,另外一种是通过 gitlab rail 命令行后台,通过

Project.find(16).disk_path // id 可以到项目设置里面看得到,不需要太高权限
Project.find_by_full_path('group/project').disk_path

都可以找到具体路径

修复

于是找到路径,查看项目的 c5 路径权限,权限果然不对,所有者居然是 root 不是 git,导致 git 写入失败,最终通过修改文件夹所有者改为 git 之后,提交成功

gitlab hash 文件夹文档:https://docs.gitlab.com/ee/administration/repository_storage_types.html
https://docs.gitlab.com/ee/user/admin_area/index.html#administering-projects
https://docs.gitlab.com/ee/administration/operations/rails_console.html#starting-a-rails-console-session

Linux 文件夹权限说明:
https://www.cnblogs.com/sxdcgaq8080/p/7498906.html

git push 失败 Stack Overflow 资料:
https://stackoverflow.com/questions/42214667/what-does-git-mean-by-unable-to-migrate-objects-to-permanent-storage
https://stackoverflow.com/questions/49627374/git-remote-rejected-unable-to-migrate-objects-to-permanent-storage