简体   繁体   中英

Resolve merge conflict in gerrit/git

At work we use gerrit for codereview and as a git server. Also we have the following workflow:

  1. For each feature create a new feature branch
  2. If feature is ready, push it to git push origin HEAD:refs/for/feature for codereview
  3. After codereview, submit your change and merge origin/feature in your local master: git checkout master && git merge --no-ff origin/feature
  4. After resolving all conflicts push it a second time to gerrit git push origin HEAD:refs/for/master
  5. If the change from step 4 is okay, submit it.

Problem: Lets say everything works smooth until step 5. My change was reviewed and I´m ready to submit the change. In the meantime another developer pushes some changes directly to master. Gerrit gives me now a "merge conflict" in my change without the option to submit my change.

Now i´ma little bit lost in how I should resolve this issue...at the moment I can only come up with the following three solutions:

  1. Checkout the change and git rebase origin/master (losing my previous merge commit, rewriting history)
  2. Checkout the change and git rebase --rebase-merges origin/master (rewriting history)
  3. Checkout the change and 'git merge --no-ff origin/master' (history is a little bit f*cked up...)

Is there a safe and elegen solution to this problem? How would you solve it? I´m quite new to git/gerrit and dont want to mess up our repo...

I'd recommend a workflow that relies on rebasing. That is, your solution 1.

I would also recommend periodically rebasing to HEAD between steps 1 and 2 during development to minimize surprises at review time.

Generally this makes it easier to understand the change as a simple application of your commits. I find it is generally much easier from the perspective of the reviewer too, and also for everyone to reason about should there ever be a need to roll back a change.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM