问题
Working on a feature branch in Gerrit, I want to push my feature branch changes to master (so others can make use of it) as well as to my feature branch (so I can keep working on it without the changes on master), but once I've pushed to one, I can't gerrit push to the other.
For example, if I git push HEAD:refs/for/master
then a subsequent git push HEAD:refs/for/feature
will result in:
Total 0 (delta 0), reused 0 (delta 0)
remote: Processing changes: refs: 1, done
To ssh://gerrit.server/repo.git
! [remote rejected] HEAD -> refs/for/feature (no new changes)
error: failed to push some refs to 'ssh://gerrit.server/repo.git'
Of course there are new changes, but only with respect to a different branch.
At the moment, I have two options:
Push to the feature branch, get it tested, reviewed & submitted, then manually merge it into master and get that tested, reviewed & submitted.
- The problem here is that if other changes are merged into master between my pulling master to do the merge and my merge commit being submitted, then we end up with an extra unnecessary merge.
Push to master, get it tested, reviewed & submitted, then get our gerrit guru to update the feature branch ref in gerrit to the where it needs to be.
- Apart from being a hack, with the potential to go badly wrong, it isn't something you would want to have to ask someone to do very often.
- The CI server only runs tests on master, not on the branch.
Neither of these solutions is very satisfactory.
Ideally I would like to just push to the feature branch, and then push to master and have gerrit realise that the second push was to get the commit (or commits) merged to master; or alternatively, push to master then push to the feature branch, and have gerrit realise that this is just a request to fast-forward the feature branch ref. Unfortunately I haven't found any way to do this.
Is there a clean way to push a change, or set of changes, to both their feature branch and master?
Note, we have merge based workflow rather than a rebase based workflow, so answers which rely on a rebase workflow will not be useful to us.
Having discovered Selecting Merge Base I thought the base
option might be what I was looking for, however when I try git push origin HEAD:refs/for/master
followed by git push origin HEAD:refs/for/feature%base=$(git rev-parse origin/feature)
the push to the feature branch fails in the same way as if I'd just done git push origin HEAD:refs/for/feature
i.e. it says [remote rejected]
due to (no new changes)
.
We have also tried enabling the create-new-change-for-all-not-in-target
option in the Gerrit project configuration, but it fails in exactly the same way:
$git commit -am "New commit for feature and master."
[fix 1234567] New Commit
19 files changed, 19 insertions(+), 19 deletions(-)
$git push origin HEAD:refs/for/master
Counting objects: 48, done.
Delta compression using up to 12 threads.
Compressing objects: 100% (25/25), done.
Writing objects: 100% (25/25), 2.20 KiB, done.
Total 25 (delta 24), reused 0 (delta 0)
remote: Resolving deltas: 100% (24/24)
remote: Processing changes: new: 1, refs: 1, done
remote:
remote: New Changes:
remote: http://gerrit.server/1234 New commit for feature and master.
remote:
To ssh://gerrit.server/repo.git
* [new branch] HEAD -> refs/for/master
$git push origin HEAD:refs/for/feature
Total 0 (delta 0), reused 0 (delta 0)
remote: Processing changes: refs: 1, done
To ssh://gerrit.server/repo.git
! [remote rejected] HEAD -> refs/for/feature (no new changes)
error: failed to push some refs to 'ssh://gerrit.server/repo.git'
I also tried pushing to the feature branch first and then mastedr, but as expected, this results in the same rejection.
回答1:
When it comes to Gerrit, we use slightly different approach. We do not maintain a topic branches but we use change subjects provided by Gerrit. That is, instead of git push HEAD:refs/for/feature
you can submit your changes concerning one topic with git push HEAD:refs/for/master/feature
. Gerrit treats it as this is a commit with "feature" and it will be eventually merged to the master. You can have multiple changes with the same topic (they should probably be mapped to classic, local feature branch on your dev machine). Gerrit even provides nice filtering features by change topics.
Then, as master
updates you can rebase your whole topic to the it and continue to develop the feature with code from master
. When the feature is ready, it can be merged to the master.
Such workflow enables you to test your new feature during work/review phase with the newest changes from master.
回答2:
See my answer to Gerrit with tracked feature branches: Enabling the create-new-change-for-all-not-in-target
option in Gerrit >= 2.11 to take into account target branch when determining new changes to open should also help in your case.
来源:https://stackoverflow.com/questions/36017671/gerrit-push-the-same-changesets-to-both-master-and-a-branch