On Thu, 8 Nov 2012 12:29:16 -0800 (PST)
"kramer.newsreader" <kramer.newsrea...@gmail.com> wrote:
> Hi, I made a commit and pushed it to a remote repo (gerrit).
> It turns out that my commit needs to be reverted and different
> changes need to be commited. According to our process, all changes
> for a given ticket should be pushed as an amended commit. That way
> gerrit can combine them.
> Anyway, it turns out that --amend is not an option for revert, so it
> creates a new commit.
Note that "amending" is a somewhat deceiving term as it stems from the
most typical use-case for the `git commit --amend` command: you have
just made a commit and so you have the index and the work tree matching
the committed state, so you just quickly fix up something simple, like
adding another file (or do nothing at all, to just re-edit the commit
message) and then a new commit is recorded, *replacing* the existing
The crucial part here is that "an amending commit" is absolutely
nothing special from the point of view of Git: it just literally
replaces the commit pointed to by HEAD.
Consequently, either you've entered a muddy waters of overloaded
terminology here, and "an amended commit" has some different meaning in
Gerrit (I'm not familiar with Gerrit at all) or just cook a commit with
whatever contents you're pleased with and push it instead of the
original one. Basically that should amount to something like this
(assuming you're currently have the commit you wish to "amend" checked
$ git tag precious
^^^ tag the current commit so that we could regain control over it in
case something will go wrong.
$ git reset --hard HEAD^
^^^ move the current branch pointer back one commit, zapping the wrong
commit from the history.
Now do whatever changes are required, then commit.
The new commit is no different from the Git's PoV from a commit you
could do by the means of running `git commit --amend`.
Still I think that Gerrit puts some other sense to that "amending"
thing. Quite probably you're required to record a reverting
commit first (`git revert HEAD`) and then make another commit which
would record the changes that had to be committed in the first place.