Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between git commit --amend and git rebase under gerrit

Tags:

git

gerrit

I want to change the last commit content. I can do local changes. and then execute

git commit --amend

I can also do the following:

git rebase -i HEAD~

choose the commit to edit. do local changes and then execute:

git rebase --continue
  1. is there a difference between these two commands in this scenario ?
  2. in the context of Gerrit, when gerrit's CHANGE-ID is involved ?
like image 936
stdcall Avatar asked Dec 08 '25 21:12

stdcall


2 Answers

No. They both use the previous commit as a template to generate a new commit. The Gerrit change-id is simply tracked by the line in the commit comment so provided you don't modify or remove that line Gerrit can still track this new commit as referring to that change.

like image 60
patthoyts Avatar answered Dec 10 '25 12:12

patthoyts


suppose you have 3 commits A->B->C, and you have change a file which is included in commit A, so, you should make commit A at the top

git stash /* to save your changes */

git rebase -i HEAD~3
move commit A at the bottom of commits B&C
save&exit

if you make

git log

you wil have this sequence B->C->A, you make

git add /*your changed file*/
git commit --amend

now you must return commit A back to not change gerrit dependencies list

git rebase -i HEAD~3
move commit A at the top of commit B&C
save&exit

now if you push to gerrit, you will have the same old order

like image 45
elhadi dp ıpɐɥןǝ Avatar answered Dec 10 '25 12:12

elhadi dp ıpɐɥןǝ



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!