在 GitLab 上撤消 Gerrit 推送

Undo Gerrit push on GitLab

我不小心在 GitLab 存储库上进行了 Gerrit 风格的推送。

也就是说,在我当地的分支机构,我做了:

$ git push origin HEAD:refs/for/master
Enumerating objects: 7, done.
Counting objects: 100% (7/7), done.
Delta compression using up to 8 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 3.06 KiB | 184.00 KiB/s, done.
Total 4 (delta 2), reused 0 (delta 0), pack-reused 0
To gitlab.domain-name.com:project-name.git
 * [new reference]   HEAD -> refs/for/master

当我应该做的很简单时:

$ git push -u origin branch-name

据我所知,该参考资料并未显示在 GitLab Web GUI 上的任何位置。

如何撤消此操作?我需要吗?

Git refspec 使用两个 ref (source)

  • refs/heads 跟踪本地分支机构。
  • refs/remotes/ 跟踪远程分支。

refs/for/ 是特定于 Gerrit 的命名空间,因此不应影响您的存储库,因为您没有使用 Gerrit 服务器。 (source)

您可以使用以下命令删除遥控器上的引用:

git push -d origin refs/for/master

完整演示:

$ git ls-remote
From git@gitlab.domain.tld:repository.git
9379c44dc1925987c6d2ebdd62e2c91435cf3c8a    HEAD
9379c44dc1925987c6d2ebdd62e2c91435cf3c8a    refs/heads/master

$ git push origin HEAD:refs/for/master
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 8 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 286 bytes | 286.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To gitlab.domain.tld:repository.git
 * [new branch]      HEAD -> refs/for/master

$ git ls-remote
From git@gitlab.domain.tld:repository.git
9379c44dc1925987c6d2ebdd62e2c91435cf3c8a    HEAD
a5b0640960e5a1f26e784d2f93f94f0ec29d5f51    refs/for/master
9379c44dc1925987c6d2ebdd62e2c91435cf3c8a    refs/heads/master

$ git push -d origin refs/for/master
To git@gitlab.domain.tld:repository.git
 - [deleted]         refs/for/master

$ git ls-remote
From git@gitlab.domain.tld:repository.git
9379c44dc1925987c6d2ebdd62e2c91435cf3c8a    HEAD
9379c44dc1925987c6d2ebdd62e2c91435cf3c8a    refs/heads/master