Gerrit:在页脚中修复没有change-id的提交

时间:2017-03-20 19:33:40

标签: git gerrit

我让Gerrit设置为在提交消息页脚中需要change-id。但是,我能够以某种方式在页脚中没有更改ID的情况下推动更改。这似乎弄乱了我的分支(主分支)。我现在无法推送到主分支机构。

这是我到目前为止所做的:

> git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working tree clean

> touch test.txt

> git add .

> git commit

> git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    new file:   test.txt

> git -c diff.mnemonicprefix=false -c core.quotepath=false -c credential.helper=sourcetree push -v origin master:refs/for/master 
Pushing to ssh://username@gerrit.site.com:29418/project_name
To ssh://username@gerrit.site.com:29418/project_name
 ! [rejected]        master -> refs/for/master (non-fast-forward)
error: failed to push some refs to 'ssh://username@gerrit.site.com:29418/project_name'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and integrate the remote changes
hint: (e.g. 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Completed with errors, see above

这是分支的结构:

o [origin/master][origin/HEAD][master] current head
\ \
 \ \
  \ o commit without change-id in footer
   \
    o [origin/refs/for/master] test commit to try and fix previous

1 个答案:

答案 0 :(得分:2)

让我们将您的问题分为两个主题:

在没有Change-Id的情况下提交

您已将提交直接推送到绕过Gerrit的分支。例如,通过执行以下命令之一来完成此操作:

git push origin master:master

OR

git push origin master:refs / heads / master

当您直接推送到分支时,不需要Change-Id,因为在此过程中绕过了Gerrit。避免这种错误的唯一方法是删除你的权限,推送到refs / heads / *(直接分支)。

错误推送到refs / for / master

似乎你错误地创建了一个名为“refs / for / master”的分支。我认为,如果你执行这样的命令,就会发生这个问题:

git push origin master:refs/heads/refs/for/master

在这种情况下,要解决此问题,只需使用Gerrit UI删除错误的分支:

  1. 转到项目&gt;列表
  2. 使用“过滤器”字段查找项目
  3. 点击项目名称
  4. 点击“分支”标签
  5. 选择“refs / for / master”分支
  6. 点击“删除”按钮