I usually work on files which are updated in the file system via version control. What's a quick way to reload a file without having to C-x C-f the file again and getting asked if I want to reload it?


M-x revert-buffer will do exactly what you want. It will still ask for confirmation.

Another option (my favorite) is the below function:

;; Source: http://www.emacswiki.org/emacs-en/download/misc-cmds.el
(defun revert-buffer-no-confirm ()
    "Revert buffer without confirmation."
    (revert-buffer :ignore-auto :noconfirm))
  • 8
    You might have cited the library that that code is from: misc-cmds.el. Not that it is complicated, but when you copy something exactly it is common courtesy to point to the source.
    – Drew
    Sep 24 '14 at 15:11
  • 3
    Apologies! I, myself, wasn't sure where I got that snippet from. I should have at least googled the function name and try to find its source so that I can credit it here. Update I have noted down the sources for everything I copied; just wasn't sure about this one: github.com/kaushalmodi/.emacs.d/blob/master/setup-files/… Sep 24 '14 at 15:12
  • 5
    I wouldn't recommend this function. It's too dangerous to use accidentally on a modified file. Sep 27 '14 at 0:13
  • 2
    @Gilles I agree, with great power comes great responsibility. I wouldn't bind that to an easy to access binding. Sep 27 '14 at 0:44
  • 8
    My variant of this will prompt for confirmation only if the buffer is modified, using (revert-buffer t (not (buffer-modified-p)) t).
    – glucas
    Jul 10 '15 at 15:23

There is also auto-revert-mode which does it automatically and gives you feedback.

From the doc string:

auto-revert-mode is an interactive autoloaded compiled Lisp function
in `autorevert.el'.

(auto-revert-mode &optional ARG)

Toggle reverting buffer when the file changes (Auto Revert mode).
With a prefix argument ARG, enable Auto Revert mode if ARG is
positive, and disable it otherwise.  If called from Lisp, enable
the mode if ARG is omitted or nil.

Auto Revert mode is a minor mode that affects only the current
buffer.  When enabled, it reverts the buffer when the file on
disk changes.

Use `global-auto-revert-mode' to automatically revert all buffers.
Use `auto-revert-tail-mode' if you know that the file will only grow
without being changed in the part that is already in the buffer.
  • How can I enable auto-revert-tail-mode doing : (setq auto-revert-tail-mode 1)?
    – alper
    Oct 1 at 15:19

Another option, which I use, is find-alternate-file bound to C-x C-v. This opens a file reusing your current buffer.

By default, it points to the file you're currently on, so you can just type C-x C-v RET to reload your file. It won't prompt unless your buffer has unsaved data.

Some non-text modes like image-mode (used for rendering pictures, pdfs, svgs...etc) and dired have revert-buffer bound to g for faster access.

  • 4
    This is my new go to. Thanks for mentioning it.
    – ramsey_tm
    Nov 10 '16 at 15:54
  • I had a (ffap-bindings) in my .emacs which seems to change the binding of C-x C-v.
    – ychaouche
    Jan 10 '18 at 14:34
  • 1
    This should be the accepted answer.
    – Toon Claes
    Jun 26 '19 at 10:01
  • 1
    I like that is short and nice, but unlike the revert-buffer it resets point position in the buffer.
    – lks128
    Sep 28 '20 at 10:32
  • 1
    @ijoseph Haha, that's a good point—didn't think of it myself because I unbound C-x C-c years ago :P Apr 10 at 0:39

Emacs calls this reverting.

You can revert the current file with M-x revert-buffer. This prompts for confirmation whether the file has been modified or not, except for files that match patterns listed in the variable revert-without-query (see the manual for details). Another occasional annoyance of revert-buffer is that it resets the file mode to the default.

I use the following function to revert a bunch of files, given by name. If a file isn't opened in some buffer, it is ignored.

(defun revert-files (&rest files)
  "Reload all specified files from disk.
Only files that are currently visited in some buffer are reverted.
Do not ask confirmation unless the buffer is modified."
    (let ((revert-without-query '("")))
      (dolist (file-name files)
        (message "Considering whether to revert file %s" file-name)
        (let ((buf (find-buffer-visiting file-name)))
          (when buf
            (message "Reverting file in buffer %s" (buffer-name buf))
            (set-buffer buf)
        (revert-buffer t nil t)))))))

A typical use case for this function is after updating files from version control. Use emacsclient to call revert-files on all the files that have been updated, or (this is easier, and only slightly slower) on all the files concerned by the update. I call the following shell script, passing it the files as arguments:

#! /bin/sh
# Similar to gnuclient, but call `revert-files' on the files.

## Find a way to convert a path to absolute. Bizarre OSes such as Windows
## require special cases. We also try to detect non-filenames such as URIs.
case `uname -s` in
    absolute_path () {
      cygpath -a -w -- "$1"
    wd="`pwd -P 2>/dev/null || pwd`"
    absolute_path () {
      case "$1" in
        /*) printf '%s' "$1";; # ordinary absolute path
          if expr "z$1" : 'z[0-9A-Z_a-z][-.0-9@A-Z_a-z]*:/.*'; then
            printf '%s' "$1" # URI or machine:/some/path
            printf '%s' "$wd/$1" # default to a relative path
        *) printf '%s' "$wd/$1";; # default to a relative path

for x; do
  files="$files \"`absolute_path "$x" | sed 's/[\\\\\\\"]/\\\\&/g'`\""
exec emacsclient -e "(revert-files$files)"

Usage example:

svn update
find -name .svn -prune -o -type f -exec emacsclient-revert {} +
  • These days, as @webappzero says in his answer, magit solves this part of the file-reverting problem painlessly Nov 13 '18 at 21:32

you can also enable global-auto-revert-mode as shown below

(global-auto-revert-mode 1)

this is helpful when you do a lot of checks of your js files with auto-fix mode enabled, like in jssc.


revert-buffer is there. But I like to have some feedback.

I have the following in my .emacs.

(global-set-key (kbd "C-c r") (lambda ()
                                (revert-buffer t t t)
                                (message "buffer is reverted")))

You can use find-alternate-file, which is bound to C-x C-v by default, and just simply type RET at the prompt to reload the file.


For spacemacs users: SPC b R (spacemacs/safe-revert-buffer).

For skipping confirmation, other answers already cover that, though I agree with others that it's probably not a good idea to bind that to a key.


Magit manages file reversions for you automatically, thus solving your core problem. You also benefit from its other features.

Here are the docs for the tweaking the settings you're interested in:

If you stick with Magit, also be sure to enable all 3 global WIP modes (Work In Progress) to avoid losing work.

You can thus perform version-control actions inside Emacs with Magit and avoid your original problem altogether.

  • 1
    Please let me know if this is helpful.
    – webappzero
    Aug 14 '17 at 23:33
  • This answer should have more upvotes! In case not clear: the WIP modes may be good (I don't use them currently), but they're not strictly necessary in order for it to solves the revert problem for you. Nov 13 '18 at 21:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.