Gerrit: is there a way to push just the top commit to the same branch?

Question

After searching for a light and finding quite a few similar questions, none of them seemed to really answer my question (below a list of related questions I found).

I am developing further changes on top of a commit not yet reviewed, but I want to keep the changes separate. When trying to push the new patch for review, I get the error:

! [remote rejected] HEAD -> refs/for/master (no changes made)

Scenario: In my branch I have Commit A (merged) <-- Commit B (cherry-picked/unmerged) <-- Commit C (with recent changes I want to push).

As mentioned, Commit C is dependent of B (but as I want them separate, a squash cannot be done. Also removing B is not an option, as it adds changes not yet present is C).

So when I try to push Commit C for review I get the error message above (I understand that is due to Commit B being below the new Commit C).

My question is: is there a way to send only Commit C up to Gerrit, before Commit B gets merged? Or I really must wait for B to be merged so I can send Commit C up?

Homework:

Gerrit workflow - push single commit to topic branch

Git / gerrit, push remote rejected no changes made

Is there a way to force Gerrit to have all commits in a branch be push to code review?

git - pushing only the top most commit to server


Show source
| git   | gerrit   2017-01-02 21:01 2 Answers

Answers to Gerrit: is there a way to push just the top commit to the same branch? ( 2 )

  1. 2017-01-02 23:01

    Yes, you can push commit-C based on unmerged commit-B but you can't cherry-pick it because that way you get commit-C based on commit-B' (a different commit which has no changes when compared with original commit-B.

    Try this procedure:

    1. Checkout the unmerged commit-B (copy this command from Gerrit > Change > Download > Checkout):

      git fetch https://USER@SERVER/a/REPO-PATH/REPO-NAME refs/changes/X/Y/Z && git checkout FETCH_HEAD

    2. Create a branch from commit-B

      git checkout -b some-branch

    3. Make commit-C change, commit and push to Gerrit

    I think Gerrit will create a change with commit-C based on commit-B from previous change. Be aware that if someone change the original commit-B you will need to rebase your commit-C before it can be merged.

  2. 2017-01-02 23:01

    Another option may be to simply combine (squash) both commits into one while you are developing (in a separate change-set from B) and once B is merged you can rebase on top of master which will just leave your unique changes.

Leave a reply to - Gerrit: is there a way to push just the top commit to the same branch?

◀ Go back