Martin G
Martin G

Reputation: 18129

How to rebase a merge but keep the merge commit

Me and my team are developing a feature using a remote branch (origin/our_feature_branch) off of main track (origin/dev). Gerrit is used for review etc.

Uplifting the remote branch is done with git merge origin/dev followed by fixing conflicts, committing and git push origin HEAD:refs/for/our_feature_branch.

Gerrit enforces a rule saying that only one commit at a time can be pushed. I cannot do anything about this.

Say I start working on doing an uplift:

git fetch
git checkout -b uplift origin/our_feature_branch
git merge origin/dev

But here I get stuck fixing some conflicts and the regression tests take some time to run, and some team member submits another commit to the feature branch in Gerrit. This commit is now on top of the base commit for my "ongoing" uplift.

What do I do now?

If I rebase my merge commit on the feature branch I remove the merge and add all commits merged in from origin/dev on top of it - not an option. If I merge with the feature branch I will end up with a merge on a merge and I will end up having to push two commits to Gerrit - also not allowed.

Is there a solution to this or do I have to re-do the merge and try to remember to tell everyone that we have a delivery stop next time I start working on an uplift?

Upvotes: 2

Views: 3525

Answers (1)

Martin G
Martin G

Reputation: 18129

As suggested in comments, git rebase -p solves the issue

Start to create the uplift commit:

git fetch
git checkout -b uplift origin/our_feature_branch
git merge origin/dev
git commit

Something is submitted to origin/our_feature_branch in Gerrit.

Do the following to rebase the merge commit and keep the merge:

git fetch
git rebase -p origin/our_feature_branch

Now the merge commit can be pushed to Gerrit and it will be based on latest on origin/our_feature_branch and the same origin/dev as before the git rebase -p

Upvotes: 3

Related Questions