32.10.2 开发者向审核服务器提交

由Gerrit控制的Git版本库不能直接提交,因为正确设置的Gerrit服务器,会拒绝用户直接向refs/heads/*推送。


$git status

On branch master

Your branch is ahead of 'origin/master' by 1 commit.

#

nothing to commit(working directory clean)

$git push

Counting objects:5,done.

Writing objects:100%(3/3),332 bytes,done.

Total 3(delta 0),reused 0(delta 0)

To ssh://localhost:29418/hello.git

![remote rejected]master->master(prohibited by Gerrit)

error:failed to push some refs to 'ssh://localhost:29418/hello.git'


直接推送就会遇到"prohibited by Gerrit"的错误。

正确的做法是向特殊的引用推送,这样Gerrit会自动将新提交转换为评审任务。


$git push origin HEAD:refs/for/master

Counting objects:5,done.

Writing objects:100%(3/3),332 bytes,done.

Total 3(delta 0),reused 0(delta 0)

To ssh://localhost:29418/hello.git

*[new branch]HEAD->refs/for/master


看到了吗,向refs/for/master推送成功。