git Gerrit 重新创建更改 ID

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7893854/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 12:09:37  来源:igfitidea点击:

Gerrit recreating change-ids

gitgerrit

提问by Frank Sposaro

I am using gerrit. I used the following command

我正在使用gerrit。我使用了以下命令

$ cd .git/hooks
$ scp -P 29418 demo@localhost:hooks/commit-msg .
$ cd ../..

This adds the change-id to my commit message, however if I amend to a commit it creates a NEW change-id. So when I push back to gerrit it's not adding the patch set, it's creating a whole new review entry.

这会将更改 ID 添加到我的提交消息中,但是如果我修改提交,它会创建一个新的更改 ID。因此,当我推回 gerrit 时,它没有添加补丁集,而是创建了一个全新的评论条目。

Any suggests please?

请问有什么建议吗?

Found the answer, but stackoverflow won't let me answer my own question.

找到了答案,但 stackoverflow 不允许我回答我自己的问题。

So this was a complete error on my part. When I was trying to commit git commit --amend -m "Initial Commit"

所以这对我来说是一个完整的错误。当我试图提交 git commit --amend -m "Initial Commit"

I was inlining the commit message and that was wiping away the change-Id, thus giving me a new one.

我正在内联提交消息,这抹去了更改 ID,从而给了我一个新的。

回答by Tomasz Wysocki

commit-msg hook work that way:

commit-msg 钩子是这样工作的:

  1. Check if you have change-id in your commit message.
  2. If not, generates one.
  1. 检查您的提交消息中是否有更改 ID。
  2. 如果不是,则生成一个。

If you type git commit --amendand edit commit message, you still have old change-id (it is good).

如果您输入git commit --amend并编辑提交消息,您仍然拥有旧的更改 ID(很好)。

But if you type git commit --amend -m "...."you have removed change-id, so gerrit generates new one.

但是如果你输入git commit --amend -m "...."你已经删除了change-id,那么gerrit会生成一个新的。

Rule of a thumb: Don't use --amend -mwith gerrit.

经验法则:不要--amend -m与 gerrit 一起使用。

回答by Abhijeet

If git commit --amendor git commit --amend -m "...."doesn't help and gerrit still complains about the missing change-Id. (This happens due to network issues mostly)

如果git commit --amendgit commit --amend -m "...."没有帮助,gerrit 仍然会抱怨缺少更改 ID。(发生这种情况主要是由于网络问题)

This is how I got it resolved (Made sure I had the commit-msg hook applied, on parent directory of the checked-out directory reference):

这就是我解决它的方法(确保我在检出目录引用的父目录上应用了 commit-msg 钩子):

  1. Stash the Changes using git stash.
  2. Used gitk &to hard rebase the change to just previous commit. enter image description here
  3. Then pull and rebase from Repo git pull --rebase.
  4. Then apply the stashed changes using git stash apply, reference. Resolve Merger Conflicts if any using git mergetool.
  5. Recommitted in the change again using git commitor git commit --amend, this generated a new change-Id
  6. Push the changes to branch on repository using git push ...command.
  1. 使用 存储更改git stash
  2. 用于gitk &将更改硬重新设置为之前的提交。 在此处输入图片说明
  3. 然后从 Repo 拉取和变基git pull --rebase
  4. 然后使用git stash apply, reference应用隐藏的更改。解决合并冲突(如果有)使用git mergetool.
  5. 再次使用git commitor重新提交更改git commit --amend,这生成了一个新的更改 ID
  6. 使用git push ...命令将更改推送到存储库上的分支。

There is similar question around as well for reference

也有类似的问题供参考

回答by drgnfr

  1. git commit --amend
  2. Manually delete the Change-Idline, save and close
  3. git commit --amend --no-edit
  1. git commit --amend
  2. 手动删除Change-Id行,保存关闭
  3. git commit --amend --no-edit

And the hook will create a new Change-Id hash, in the absence of one.

如果没有,钩子将创建一个新的 Change-Id 哈希。