git push origin HEAD:ref/for/master 每次都会创建一个新的提交而不是修改以前的更改

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21201858/
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-19 09:36:17  来源:igfitidea点击:

git push origin HEAD:ref/for/master creates a new commit everytime instead of amending previous changes

gitgerrit

提问by nirajkumar

This question is related to the git/gerrit push command

这个问题与 git/gerrit push 命令有关

When I submit my changes to the git/gerrit with the following command

当我使用以下命令向 git/gerrit 提交更改时

git commit
git push origin HEAD:ref/for/master

It creates a commit.

它创建一个提交。

Now if I want to amend any changes(creating a patch ).
I modify the file and uses the following command

现在,如果我想修改任何更改(创建补丁)。
我修改文件并使用以下命令

git commit --amend
git log

It amends the detail in the same previous commit

它修改了上一次提交中的细节

But when I try to push it to the remote master with the following command

但是当我尝试使用以下命令将其推送到远程主机时

git push origin HEAD:ref/for/master

It creates a new gerrit commit instead of creating a patch for the previous commit

它会创建一个新的 gerrit 提交,而不是为之前的提交创建补丁

Am I missing something?

我错过了什么吗?

回答by VonC

git commit --amend works, but, as mentioned here:

git commit --amend 有效,但是,正如这里提到的

you need to add the gerrit change-idat the bottom of your commit message (Change-Id: 234j243rasdf...) right before the git #'ed commit description and the change will be patched onto your previous commit –

您需要change-id在提交消息 ( Change-Id: 234j243rasdf...)底部的 git #'ed 提交描述之前添加 gerrit ,更改将被修补到您之前的提交中 –

See more about Change-Id in the Gerrit documentation.

Gerrit 文档 中查看有关 Change-Id 的更多信息。

Change Upload

更改上传

During upload by pushing to a refs/for/*or refs/heads/*branch, Gerrit will use the Change-Id line to:

  • Create a new change:
    If this is the first time it has seen the Change-Id mentioned in the commit message, Gerrit will create a new change for review.
  • Update an existing change:
    If Gerrit has seen this Change-Id before, but has not yet seen this new commit object, Gerrit will add the new commit as a new patch set on the existing change.
  • Close an existing change:
    If Gerrit has seen this Change-Id before, and the commit is being pushed directly into a branch, the existing change is updated with the new commit, and the change is closed and marked as merged.

在通过推送到 arefs/for/*refs/heads/*分支的上传过程中,Gerrit 将使用 Change-Id 行来:

  • 创建一个新的更改
    如果这是第一次看到提交消息中提到的 Change-Id,Gerrit 将创建一个新的更改以供。
  • 更新现有更改
    如果 Gerrit 之前已经看到此 Change-Id,但尚未看到此新提交对象,则 Gerrit 会将新提交添加为现有更改上的新补丁集。
  • Close an existing change
    如果 Gerrit 之前已经看到过这个 Change-Id,并且提交被直接推送到一个分支,那么现有的更改会用新的提交更新,并且更改被关闭并标记为已合并。

回答by redcom

You can safely use git commit --amend --no-edit Without --no-edit it will alter the message, checksum and you will end up having a new commit id.

你可以安全地使用 git commit --amend --no-edit 如果没有 --no-edit 它会改变消息、校验和,你最终会有一个新的提交 ID。

回答by luatnt

I think that the true command to create a patch for the previous commit is: git push origin HEAD:refs/changes/

我认为为上一次提交创建补丁的真正命令是: git push origin HEAD:refs/ changes/

for example: git push origin HEAD:refs/changes/1234

例如:git push origin HEAD:refs/ changes/1234

To get the commit's gerrit code, you need to login to gerrit and find your commit in "My -> changes" menu, the commit's gerrit code will appear at the end of the link in the address bar of the browser, for example, with below link: http://10.207.215.71:81/#/c/5678/ the gerrit code will be "5678"

要获取提交的gerrit代码,您需要登录gerrit并在“我的->更改”菜单中找到您的提交,提交的gerrit代码将出现在浏览器地址栏中的链接末尾,例如,以下链接:http: //10.207.215.71 : 81/#/c/ 5678/ gerrit 代码将为“ 5678