diff-hl-mode highlights uncommitted changes on the left side of the
window (area also known as the "gutter"), allows you
to jump between and revert them selectively.
In buffers controlled by Git, you can also stage and unstage the changes.
For the usage instructions and the list of commands, see the Commentary section inside the file.
Tested with Git, Mercurial, Bazaar and SVN. May work with other VC backends, too.
The package also contains auxiliary modes:
diff-hl-dired-modeprovides similar functionality in Dired.
diff-hl-margin-modechanges the highlighting function to use the margin instead of the fringe.
diff-hl-amend-modesets the reference revision to the one before recent one. Also, you could use
diff-hl-set-reference-revto set it to any revision, see its docstring for details.
diff-hl-flydiff-modeimplements highlighting changes on the fly.
diff-hl-show-hunk-mouse-modemakes fringe and margin react to mouse clicks to show the curresponding hunk. That's the alternative to using
Put this into your init script:
You must also ensure that VC is enabled (e.g.
Check out the Commentary section in each file for more detailed usage instructions.
Top window: a buffer in this minor mode, bottom window: the corresponding diff.
diff-hl-mode uses the corresponding VC diff command, so
it's only accurate when the buffer is in saved state. Check out
diff-hl-flydiff-mode, it aims to handle unsaved buffers as well.
To use an
alternative diff algorithm
with Git, add a corresponding argument to
(setq vc-git-diff-switches '("--histogram")). Using the
diff.algorithm option doesn't work
not support alternative algorithms, because it uses the external
We conflict with other modes when they put indicators on the fringe, such as Flycheck. This is rarely a significant problem, since if you're using such a mode, you'd usually want to fix all errors and warnings before continuing, and then the conflicting indicators go away.
There's no fringe when Emacs is running in the console, but the navigation
and revert commands still work. Consider turning
to show the indicators in the margin instead.
Frame-local and buffer-local values of
line-spacing are not supported.
Fringe width up to 16 works best (because we can't define a bitmap with width above that number).
emacs-git-gutter shows indicators in the margin by default, allows you to customize how the indicators look more easily, and has a "stage hunk" command.
If you're using some package other than
vc to commit changes, it might
vc-checkin-hook after commits. In that case, you'll need to
diff-hl-update to the hook it does run, or advise some
function that's called in the buffer after its state has changed.
(advice-add 'svn-status-update-modeline :after #'diff-hl-update)
If you're using a version before 2.4.0, it defines
magit-not-reverted-hook), which we use.
When using Magit 2.4 or newer, add this to your init script:
(add-hook 'magit-pre-refresh-hook 'diff-hl-magit-pre-refresh) (add-hook 'magit-post-refresh-hook 'diff-hl-magit-post-refresh)
diff-hl should just work with Tramp. But slow or high latency
connections can cause performance problems. If you experience such
t. This will change
the behavior of both
(whichever you prefer to use).