2

I'm new to Git and even newer to Gerrit and got a little bit lost. My workflow was probably standard: create a new branch, do the magic, commit changes, push them to Gerrit's repo.

My newly pushed branch is visible in Gerrit's web UI, but change is not visible at all.

After reading this answer, Gerrit's docs and many more, I easily and quickly found, that I missed magical refs. Instead of git push origin HEAD:refs/for/{branch name} I did just git push origin.

Great! But, how to recover from this situation? Whenever I try to push again, this time with proper refs, I'm getting ! [remote rejected] (no new changes).

What does this mean and what can I do? Does it mean, that I can't fix this in any other way, than adding new changes, committing them and pushing again? (no, even pushing another commit didn't solve the problem, Gerrit merged new push into master, but completely dropped previous one; this is beyond my imagination, unfortunately!)

Community
  • 1
  • 1
trejder
  • 17,148
  • 27
  • 124
  • 216
  • By pushing one or more commits to `refs/heads/branchname` you bypass the review and push the changes straight to the branch. Unless you're in your own little local playground, you don't _want_ to "recover" from this situation as you'd be changing the branch history by rewinding the branch to an old state. Doing that is disruptive for other folks working against the same branch, and even having permissions to perform that operation is dangerous since it's too easy to make really harmful mistakes. – Magnus Bäck Dec 16 '13 at 15:02

1 Answers1

2

You can:

  • delete the remote branch by git push origin :<branch>,
  • remove the commit from local branch git reset --soft HEAD^,
  • stash the modifications by git stash,
  • create the remote branch with you local branch by git push origin <branch>,
  • get back the uncommitted changes by git stash pop,
  • commit it, and push it to refs/for/<branch>.
trejder
  • 17,148
  • 27
  • 124
  • 216
laplasz
  • 3,359
  • 1
  • 29
  • 40
  • perhaps stash is not necessary since the uncommited change will be kept after creating the remote branch – laplasz Dec 16 '13 at 10:39