30.1.12.11 Rewinding Branches

M-x vc-delete-revisions-from-end

Delete revisions from the end of the current branch.

M-x vc-uncommit-revisions-from-end

Delete revisions from the end of the current branch without touching the working tree.

For decentralized version control systems (see Decentralized vs Centralized Repositories), these commands provide ways to move the current branch back to an earlier revision. vc-delete-revisions-from-end prompts for a revision, then removes all revisions from the end of the branch up to but not including the specified revision. We say that the branch is rewound back to the specified revision.

This command removes the changes made by the revisions from the working tree. Therefore, if there are any uncommitted changes, they must be reverted, first (see Undoing Version Control Actions). This command will prompt you to do that if necessary. If you supply a prefix argument, Emacs will delete uncommitted changes without prompting.

To “uncommit” a revision means to remove it from the revision history without removing its changes from the working tree. It is as though you had made the changes but had not yet checked them in. The command vc-uncommit-revisions-from-end prompts for a revision, and then uncommits all revisions from the end of the branch up to but not including the specified revision. The branch is rewound back to the specified revision but the changes are left behind in the working tree.

When rewinding the current branch, if all the revisions deleted from the revision history are among those you have pulled or pushed, then these operations do not permanently delete anything: a simple C-x v + (see Pulling/Pushing Changes into/from a Branch) will bring the revisions back. On the other hand, if there are new revisions on the end of the branch that have not yet been pushed, then these commands will delete them permanently. Emacs tries to detect this situation and ask you if you are sure you want to delete them.

Alternative ways to access this functionality are the log-view-uncommit-revisions-from-end and log-view-delete-revisions-from-end commands, bound to x and X, respectively, in Log View mode buffers (see VC Change Log). Compared to using the commands described here directly, the Log View mode commands can make it easier to be sure you are rewinding back to the revision you intend.