Home > Enterprise >  Why can't I checkout another two changes and make a new one
Why can't I checkout another two changes and make a new one

Time:03-31

My team is working with Gerrit.

Now, two colleagues and I are working on a some project.

Both of them have git push to Gerrit, meaning that there have been two independent Changes on Gerrit.

Now, I need to get their changes, merge them into my local project, and push a new Change to Gerrit.

Let's say the two existing changes are A and B.

On my local machine, I do things as below:

git checkout master && git pull
git fetch ... refs/changes/xx/xxxxxx/x && git checkout FETCH_HEAD # checkout A from Gerrit
git switch -c br_a
git fetch ... refs/changes/xx/xxxxxx/y && git checkout FETCH_HEAD # checkout B from Gerrit
git switch -c br_b

Now, I have two local branches br_a and br_b, which contain the changes A and B.

Then I switch to my own local branch, which contains my own changes: git checkout br_c.

After that, I do git merge br_a and git merge br_b to merge the changes of A and B into my local branch br_c. (I resolved all of conflicts.)

Then I need to push all of these to Gerrit.

So I execute git commit and git push origin HEAD:refs/for/master.

However, I got the error.

remote: Resolving deltas: 100% (26/26)
remote: Processing changes: refs: 1, done
remote:
remote: ERROR:  In commit 1111111098b751266c11111222222a33ce0b83
remote: ERROR:  author email address [email protected]
remote: ERROR:  does not match your user account.
remote: ERROR:
remote: ERROR:  The following addresses are currently registered:
remote: ERROR:    [email protected]
remote: ERROR:
remote: ERROR:  To register an email address, please visit:
remote: ERROR:  http://gerrit.xxxx.yyyy.com/#/settings/contact
remote:
remote:
To http://gerrit.xxxx.yyyy.com/a/xxx_project
 ! [remote rejected]     HEAD -> refs/for/master (invalid author)
error: failed to push some refs to 'http://gerrit.xxxx.yyyy.com/a/xxx_project'

[email protected] is one of the two colleagues, so it seems that git merge bring some metadata of A and/or B into my local branch so that I can't push.

I've tried git commit --amend, delete the Change-id and/or reset the author and email, but that doesn't help.

CodePudding user response:

Gerrit has 2 permissions, Forge Author and Forge Committer. When you push a commit for review, Gerrit validates if the author email and committer email match the email address registered in your Gerrit username. If they don't match, the push is rejected. You used git merge to apply commits. The author and committer identity lines are not changed, and don't match yours. So the push failed.

Here are 2 solutions. One is to ask the Gerrit administrator to grant you the 2 permissions so that you can push commits made by others. The other is to apply the patches without preserving the author and committer identities, by git merge --squash or git cherry-pick -n or git apply or manually modifying the files.

  • Related