Amending is possible only for the latest commit. Let's assume that the commit you wand to amend is called (has a SHA-1 code) 111
. You can see the real SHA-1 code of your commit in git log
.
You can use git reset --hard
to make your local branch point to the commit you want to amend. Note that with "plain" git without Gerrit it would be a very bad idea as you are rewriting history by modifying already pushed commit!
I assume that you already have local, uncommitted changes to some files and you want to apply these changes to the commit 111
. You have to stash these changes, because git reset --hard
will remove them and it couldn't be undone.
So you have to do (replace master
with the name of a branch you're on):
git stash save
git reset --hard 111
git stash apply
<do some more changes to commit 111 if needed>
git commit --amend
git push gerrit master:refs/for/master
And voila - your commit 111 was amended and updated with Gerrit.
There is another way to do that - you can use git rebase --interactive
, but I find it more complicated than git reset
in this case.