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

StackOverflow https://stackoverflow.com/questions/21201858

  •  29-09-2022
  •  | 
  •  

Question

This question is related to the git/gerrit push command

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

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

Am I missing something?

Était-ce utile?

La solution

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

you need to add the gerrit change-id at 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 –

See more about Change-Id in the Gerrit documentation.

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.

Autres conseils

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.

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

for example: 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"

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top