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.

up vote 41 down vote accepted

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.

  • Exactly what I needed, thank you! – David Holm Jan 26 '15 at 9:48
  • 7
    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 Dec 11 '15 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 Aug 13 at 18:59
  • 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 Aug 13 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 Aug 14 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 Sep 18 '16 at 19:59
  • @BryanAsh yes, if the solution in C is so much easier. – Markus Strauss Apr 22 at 19:31

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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