I have merged a branch and tried to push the changes into Gerrit,
git checkout dev
git merge feature
After merging my status shows like,
$ git status
On branch dev
Your branch is ahead of 'origin/dev' by 35 commits.
(use "git push" to publish your local commits)
nothing to commit, working tree clean
Then I tried to push
git push origin HEAD:refs/for/dev
Getting below error,
! [remote rejected] HEAD -> refs/for/dev (no new changes)
Couple of SO answers (answer1, answer2, answer3) suggested to amend before push but I have many CLs which got merged. Now how can I deal with this situation?
If you need to push changes for review (to refs/for/foo
), always use git merge --no-ff
to create a merge commit. The merge commit will be reviewed, and once it's submitted, the merged branch will be introduced to the target branch.
Without a merge commit, the merged commits have already been reviewed before on the merged branch in the perspective of Gerrit. That's why Gerrit responds with no new changes
as they are not new to Gerrit.
To solve the current issue, you could try:
git reset origin/dev --hard
git merge feature --no-ff
# if your repository requires ChangeID, use "git commit --amend" to invoke the hook to generate ChangeID.
git commit --amend
git push origin HEAD:refs/for/dev