Maxx
Maxx

Reputation: 846

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

Upvotes: 1

Views: 1626

Answers (2)

mrutyunjay
mrutyunjay

Reputation: 8310

If you want to push both the changes for review, then either restore the abandoned change and try to push again or using the rebase command with interactive option (git rebase -i HEAD~2) update the commit message of abandoned change, remove the "Change ID" line from commit message so that gerrit will not try to upload a new patchset to abandoned change rather it will upload new change.

If you want to upload only latest commit then using same rebase command remove the abandoned change from your local repo.

git rebase -i HEAD~2

Upvotes: 0

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.

Upvotes: 1

Related Questions