Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

gerrit

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?

like image 922
nirajkumar Avatar asked Mar 11 '26 22:03

nirajkumar


1 Answers

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.
like image 156
VonC Avatar answered Mar 14 '26 13:03

VonC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!