Gerrit Rebase including parents

Viewed 8168

In gerrit, I usually push multiple small commits together. Once they are reviewed & ready to be submitted, I see button Submit including parents on all the changes whereas the 1st change has a Submit button.

While getting these changes reviewed, many-a-times the HEAD of target branch moves ahead of the parent commit of my changes. If I were to rebase this whole set of changes on to the current HEAD of the branch, it requires me to do it manually on my local system and again push to gerrit. I was wondering if we have some option like Rebase including parents where I could just rebase the whole chain without having to do anything on my local system (only if it has no conflicts)?

3 Answers

I was wondering if we have some option like Rebase including parents where I could just rebase the whole chain without having to do anything on my local system (only if it has no conflicts)?

No, Gerrit does not have such a feature. The only way to do this in Gerrit's UI is to individually rebase each change in the series, from the bottom up.

I have created a request on the Gerrit issue tracker to add a "rebase including parents" feature.

Gerrit 2.4 version, which introduced the rebase button, as mentioned here.

A rebase would only involve one branch, with possibly ancestor commit in parent branches.

If you have local parent branches which are changed after that rebase, the simplest way is to fetch the Gerrit repo and reset yuor local branches to the new remote branches HEAD

git branch -f myBranch origin/myBranch
git branch -f myParentBranch origin/myParentBranch

That way, the rebase is done on Gerrit side, and the reset is done locally.

If you'd like the history of the target branch to be as linear as possible, go to the Project->General page and change Submit Type as Rebase If Necessary. When you press Submit or Submit including parents, these commits will be rebased onto the current head of the target branch automatically instead of being recursively merged. Note that new patch sets are created for each change in case you need to record the commit sha1. And don't forget to sync your local branch if necessary.

git fetch origin <target-branch>
git reset FETCH_HEAD --hard
Related