Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gerrit: working with multiple branches & propagating changes

I'm trying to identify the proper way of working with multiple branches on Gerrit that would match our workflow.

The way we work with branches right now is: we have master & feature branch. Master is the branch we want to polish and make it ready for release, while feature is obviously a field of intensive work. Now, in our particular case whenever somebody works on a bug fix, they:

  • create a change targeted for master branch
  • cherry pick it to the feature branch targeted change
  • once gerrit code review completes, submit both changes.

now the way i understand cherry-pick, it selects individual commit and merges it to the current change. if that is the case, i would expect to have no merge conflicts in the end, and indeed this workflow works perfectly with just GIT. Gerrit, however, most likely due to its nature (branches are not merged remotely the way these are locally and get a different sha tag) lists a tremendous number of conflicting files in the end.

Now, I resolved all these issues by applying merge strategy (ours on feature, theirs on master), but it does not feel right: if anything was not propagated, it just got discarded.

My question is: is there a safe workflow, similar to the above one, that would in the end produce a clean merge with gerrit?

like image 221
Tomasz W Avatar asked Jul 28 '12 10:07

Tomasz W


People also ask

How do I merge changes from one branch to another in Gerrit?

Use 'git merge --no-ff' - this will create a merge commit even though it isn't necessary in your fast-forward situation. Then the merge commit can be uploaded, reviewed, verified, and merged like normal.

How do I combine Gerrit?

To do that, you click the “Submit” button in the Gerrit Web UI just as you would click the “Merge Pull Request” button in GitHub. Both, Gerrit and GitHub, allow different merge strategies, that can be enabled by project administrators.


1 Answers

I would say that it's better, in this case, to merge than to cherry pick.

A cherry pick adds the same changes but not the same commit. So while the source is the same on a cherry pick and merge the git tree is different. When the tree is different and you later do a merge git will think that the commit you previously cherry picked is missing and try to merge that change as well, even if the actual code is already there. That's probably why you get a lot of conflicts.

I would propose another way of working.

  • When you do normal work you develop on feature and push to Gerrit as normal.
  • When you do a patch (ie bug fix) on the stable production environment you do that directly on master (or local branches if you like but not on feature)
  • When the patch as been approved in Gerrit it get's merged into the real master and you can make a pull request to get that change to your local copy. Your version of master is now the same as Gerrits master
  • Now you would merge all new changes on master into feature. Make sure you do a rebase so that the patch ends up before anything you've already done on feature
  • Once it's time to deploy all new features you can merge feature into master, push to Gerrit (if you have permissions you can by pass gerrit by pushing directly to master instead of refs/for/master as these changes are already reviewed)
  • Once all changes are on Gerrits master you do a pull on your master and a merge into feature with rebase making feature a clean branch to work on. It's of course totally valid to have a new feature each release. Both work fine.
like image 60
Andreas Wederbrand Avatar answered Nov 17 '22 02:11

Andreas Wederbrand