Revert the work file(s) in the current VC fileset to the last revision
(vc-revert).
Undo the effects of an older commit.
Make a new commit which undoes the changes made by an older one.
Delete an unpushed commit from the revision history.
If you want to discard all the changes you have made to the current
VC fileset, type C-x v u (vc-revert). This will ask you
for confirmation before discarding the changes. If you agree, the
fileset is reverted.
If vc-revert-show-diff is non-nil, this command will
show you a diff between the work file(s) and the revision from which
you started editing. Afterwards, the diff buffer will either be
killed (if this variable is kill), or the buffer will be buried
(any other non-nil value). If you don’t want C-x v u to
show a diff, set this variable to nil (you can still view the
diff directly with C-x v =; see Examining And Comparing Old Revisions).
On locking-based version control systems, C-x v u leaves files unlocked; you must lock again to resume editing. You can also use C-x v u to unlock a file if you lock it and then decide not to change it.
To discard changes that have already been committed, by yourself or someone else, you can use M-x vc-revert-or-delete-revision. This is called reverting a commit. The command prompts for a revision to revert, and then the VC backend reverts it.
Most backends implement this by making a new commit which undoes the changes made by the revision. For a distributed VCS, if the commit is one that you made and have not yet pushed, Emacs will offer to delete it entirely, instead. With a prefix argument, this command will only try to entirely delete the revision, failing if it has already been pushed.
An alternative way to access this functionality is the
log-view-revert-or-delete-revisions command, bound to R in
Log View mode buffers (see VC Change Log). Compared to using
M-x vc-revision revert directly, this can make it easier to be
sure you are reverting the revision you intend.
More specific, specialized commands are M-x vc-revert-revision and M-x vc-delete-revision. The first of
these prompts for a revision and then always makes a new commit which
undoes the changes made by that revision, regardless of the VCS in use
and whether or not the revision is pushed. The second command prompts
for a revision and then always deletes it, though it will stop if the
commit has been pushed. Usually vc-revert-or-delete-revision is
sufficient, but vc-revert-revision and vc-delete-revision
can sometimes be useful for constructing particular version control
histories.