Undo Gerrit push on GitLab

111 views Asked by At

I've accidentally done a Gerrit style push on a GitLab repo.

That is, while on my local branch I did:

$ 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

When what I should have done was a simple:

$ git push -u origin branch-name

This reference does not show anywhere on the GitLab web GUI as far as I can tell.

How can I undo this? Do I need to?

2

There are 2 answers

0
Matt On BEST ANSWER

You can delete the reference on the remote with the following command:

git push -d origin refs/for/master

Full demo:

$ git ls-remote
From [email protected]: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 [email protected]:repository.git
9379c44dc1925987c6d2ebdd62e2c91435cf3c8a    HEAD
a5b0640960e5a1f26e784d2f93f94f0ec29d5f51    refs/for/master
9379c44dc1925987c6d2ebdd62e2c91435cf3c8a    refs/heads/master

$ git push -d origin refs/for/master
To [email protected]:repository.git
 - [deleted]         refs/for/master

$ git ls-remote
From [email protected]:repository.git
9379c44dc1925987c6d2ebdd62e2c91435cf3c8a    HEAD
9379c44dc1925987c6d2ebdd62e2c91435cf3c8a    refs/heads/master
1
Amit Singh On

Git refspec uses two refs (source)

  • refs/heads to track local branches.
  • refs/remotes/ to track remote branches.

refs/for/ is a Gerrit specific namespace and so should not affect your repo since you are not using a Gerrit server. (source)