Search code examples
eclipsegitgerritegit

Git Push to remote rejected due to abandon change


I am facing this issue in Gerrit, Git.

  1. I made changes(branch-ONE) and pushed to gerrit(say change Id-240) from eclipse. But not merged.
  2. Next I created one more branch (branch-TWO) and commit the changes without amending to previous commit. So got new gerrit change Id (say, change id-241).
  3. Next, I abandoned the changeId 240.
  4. Now, when i try to push my changes from branch-TWO, it says remote rejected as it is trying to push to changeid 240 instead of 241. Why?

What I tried --

After reading through internet of possible solutions, I did HARD reset and my changes of changeId-241 got vanished. I though got it back from reflog. But moment, when I try to checkOut branch-ONE (to do HARD Reset), my changes of changeId-241 is vanished.

I am trying to follow this - Git merge pending due to an abandoned commit


Solution

  • It's impossible to know for sure what you have done but it seems you have something like this:

    BASE --- COMMIT-1              <= branch-1
                    \
                     \--- COMMIT-2 <= branch-2
    

    The COMMIT-2 on branch-2 depends on COMMIT-1 on branch-1 so when you push COMMIT-2 to Gerrit automatically you also push COMMIT-1. Gerrit will reject COMMIT-1 because change 240 is abandoned.

    You should have worked in parallel instead, like this:

    BASE --- COMMIT-1 <= branch-1
       \
        \--- COMMIT-2 <= branch-2
    

    This way the COMMIT-2 wouldn't depend on COMMIT-1 so you could amend the commits as you need and submit/abandon their changes in Gerrit as you wanted.