I was trying to push a new patch set to an existing change under review in Gerrit with:
git push origin HEAD:refs/for/foo
but it failed with an error that the change was already closed. Then, I foolishly tried:
git push . HEAD:refs/for/foo
which seemed successful, but when I checked Gerrit, there was no new patch set. I think part of the reason was that my commit comment did not contain the Gerrit change ID that I wanted to push to. But what did the last command actually do? And how can I undo it?
The “
.” argument means “push to this repository”, and the refspecHEAD:refs/for/foomeans “take the current commit that HEAD is pointing to, and make a new ref (similar to a branch, although those are usually stored asrefs/heads/something) namedrefs/for/foothat points to the same commit”.Essentially, it’s creating a new “branch” at the current commit, but since the desired name isn’t in the normal branch name-space, we can’t just use
git branch refs/for/foo.You should be able to undo it with
git push . :refs/for/foo– naming an empty source to replace the ref with.