Is it possible to open a specific revision of a file in Emacs with Magit without changing the current branch?

I have rebased some local changes to a revision where the modified functions were replaced by functionality in a different file. I would like to open the old revision of my changes in a separate buffer so I can compare the changes side by side.

My current hacky solution has been to run git show <branch pre-rebase>:file > old_file and then open old_file in Emacs.


2 Answers 2


You can view a file for a specific revision using M-x magit-find-file RET <filename> RET.

Or you can first view the diff for commit by pressing RET on it, navigating to the file inside the diff, and then pressing RET again.

  • 16
    This works for me; here's what I do: from the current version of the file, M-x magit-log-buffer-file, move the line to the desired commit, then M-x magit-find-file. Then the default value will be that commit. I do have to give the path to the file as this is not picked up from the log buffer.
    – Liam
    Commented Dec 11, 2015 at 17:31
  • @tarsius, Somewhat like magit-find-file but where I only need to select the revision for the current buffer's file. Does it exist already?
    – ergosys
    Commented Aug 13, 2018 at 18:59
  • 1
    Yes, use magit-find-file itself from a file-visiting buffer and then just type RET at the second prompt (the proper file is offered as the default).
    – tarsius
    Commented Aug 13, 2018 at 22:40
  • Thanks for the info and all all your work on Magit. It wasn't too difficult to hack a function that skips that pesky extra keystroke, so I'm happy until the next itch occurs.
    – ergosys
    Commented Aug 14, 2018 at 5:25

It's possible to do with plain VC (built-in to Emacs), without Magit. Type C-x v ~ and type the version you want. It understands tags and SHA1 hashes, as well as the usual ~1 etc suffixes.

  • This is not an answer to a magit question. Would you post a C answer to a Ruby question?
    – Bryan Ash
    Commented Sep 18, 2016 at 19:59
  • 13
    @BryanAsh yes, if the solution in C is so much easier. Commented Apr 22, 2018 at 19:31
  • 3
    Brilliant, exactly what I needed, it may be off-topic but this answer certainly does the job!
    – guychouk
    Commented Dec 15, 2019 at 18:26
  • 1
    Cross-referencing with stackoverflow.com/q/25420282
    – phils
    Commented May 27, 2020 at 3:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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