I have just created a new change, that I wish to pull to Gerrit. I did it (I hope) the usual way, i.e. create new branch, do magic, commit. Now, I want to push changes to Gerrit. So...
git checkout 82-changes-and-fixes-to-files-view
git push origin HEAD:refs/for/82-changes-and-fixes-to-files-view
(crunch, crunch)
! [remote rejected] HEAD -> refs/for/82-changes-and-fixes-to-files-view (branch 82-changes-and-fixes-to-files-view not found)
Branch not found? Hm... Something came to my mind, that docs said something about manually creating a branch, via Gerrit UI, before pushing changes. Am I right? Anyway, I'm doing so. I'm creating a branch, through UI, giving it above name (82-changes-and-fixes-to-files-view
) and corresponding revision, taken from git status
(2b25fe7612f1563a78c9dc2d1574ae3dcfe9d5a1
). And, again...
git push origin HEAD:refs/for/82-changes-and-fixes-to-files-view
(crunch, cruch)
! [remote rejected] HEAD -> refs/for/82-changes-and-fixes-to-files-view (no new changes)
Eee... What am I missing? How can Gerrit claim, that there are no changes, if I actually haven't pushed any code to it yet (there is no such change, of course, of above name, recorded in neither open nor merged changes in Gerrit UI)?
The solution to this problem is to always use current HEAD's last commit ID, not the one from commit made to your branch. Using branch's last commit ID is wrong. Why -- this is beyond my imagination.
So, correct path is:
As alternative, you can simply click
Create Branch
withInitial Revision
field empty, so Gerrit will auto-fill it. Then pushCreate Branch
button again.EDIT: This answer only explains, what to do, to get change accepted by Gerrit. It doesn't explains, why in previous approach (explained in question), Gerrit is claiming, that there are no changes and does not accept the code, while it actually have not code at all (for that particular branch). For me, this is a huge bug, that leads to a code losses.(incorrect as per comment below)