Emacs Advent Calendar 23: Version Control
With VC mode Emacs provides a unified interface to many common version control systems; both centralized (e.g. subversion) and decentralized (e.g. git).
As such, it can not accomodate for all use cases, meaning that some operations still have to be performed on the command line (e.g. pushing a git repository).
When you visit a file under version control, emacs will notice that and activate VC minor mode. The modeline will show an indicator with the current revision number and other information specific to the VCS used in the background (e.g. the git branch). It will also indicate if the file has uncommited changes.
To make use of the basic VC mode functionality you will just have to
learn one single keybinding:
C-x v v will always do the "next
sensible thing". When a file is not registered with the VCS it will be
registered. The next invocation will commit it, opening a buffer for
entry of the commit log message. Pressing
C-c C-c will commit
To operate on multiple files, press
C-x v d to open a
*vc-dir* buffer. This looks similar to dired. You can mark
m and unmark them with
u. When multiple
files are marked they form a VC fileset and VC commands will operate
on them as a group. For keybindings in this buffer have a look at the
To compare a file with its base version, press
C-x v =. To
look at another revision of the current file use
C-x v ~ which
will ask for the revision number and visit it in another
C-x v g will show an annotated view of the
current file, telling when each line was changed last.
Log can be displayed either for the current VC fileset (
l) or the whole repository (
C-x v L). It is shown in a
*vc-change-log*. If it is in a compact form,
<RTE> on an entry will reveal details of the
commit. Other useful keybinding in this buffer are
a (annotate) and
d (show diff to next
If you decide to undo your current work and want to revert a file to
its base version, run
C-x v u.
For full documentation on VC mode have a look at chapter 28.1 (Version Control) of the Emacs Reference Manual.Tags: emacs
This text by Ludger Sandig is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.