Undoing and re-committing can be done with the following
recipe.
There is a *big* *red* *warning*, though. If you have already
made available the commit you are about to undo to others, and
later other people have made more commits on top of them,
merging their changes back to your repository would make the
commit history look a bit funny. You could still do this
without damaging the repository. This warning only applies to
the shape of the commit graph.
First, the easiest case. Undoing and recommitting the latest
commit in the current branch.
(1) Run "git diff HEAD" and make sure that your working tree
matches the latest commit you are about to undo. Then:
$ git reset --soft HEAD^
This leaves the working tree intact (i.e. it still has what
you to have in the commit you are "fixing").
(2) Optional. If you wanted to make changes other than commit
log, do your edit here in the working tree. When done, run
"git diff HEAD" to make sure the changes are what you want
the "fixed" commit to have.
(3) Run:
$ git commit -c ORIG_HEAD
If you made changes in (2) and have not done
"git-update-index" on them, you may want to add '-a' there.
If you are just redoing the log message you probably would
not.
This gives you the editor with the log message from the
commit you undone in step (1). Do your edit and exit the
editor as usual.
Look at the output in "gitk HEAD ORIG_HEAD" to understand what
happened. You just rewound a commit, and made a different
commit.
Harder, more cumbersome case, is when you realize that you made
a mistake a several commits ago. This is described in detail in
Documentation/howto/revert-branch-rebase. Read it.
-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html