Lii
Lii

Reputation: 12122

Create new branch for existing Gerrit change

I accidentally submitted a commit (let's call it C) for a feature (F) to Gerrit without creating a feature branch for that commit. The change commit was instead located directly on the develop branch.

I have subsequently made one more commit on my local master.

How can I update my Gerrit change so that it is on a feature branch instead of on the develop branch?

I have tried this:

  1. Checked out my local commit for feature F
  2. Created a branch feature/some_feature on the commit C
  3. Amended to commit C, but on the new branch (using the same change ID)
  4. Pushed the new feature branch to Gerrit

This updates the Gerrit change with the new content (which I can see in the web-interface). But the Branch field in the GUI still has the value develop. I would like this to change to the name of the feature branch, feature/some_feature.

(In my local repo I now have two commits for feature F, one on develop and one on feature/some_feature. This is not a problem if I just get the Gerrit change right.)

Upvotes: 0

Views: 2164

Answers (1)

There isn't a way to change the destination branch of a change. You need to abandon/revert the original change and submit another to the right branch.

First of all: have you submitted (merged) the commit or just pushed (sent to review) it? If the commit C is under review use the Abandon button to cancel it. If the commit C is already merged then use the Revert button to revert it.

Finally use the Cherry Pick button to apply the same change on the feature branch. Note: the feature branch must be previously created in Projects > YOUR-PROJECT > Branches menu.

Upvotes: 1

Related Questions