1

Working in BranchA, I frequently need to refer to a file in BranchB. The git show BranchB:path/to/file command will dump the contents of file to the terminal, but that's hard to read and navigate. I'd like to have BranchB:path/to/file open in an Emacs window.

The top comment on this answer indicates that I can do this with vim by git show branch:file | vim -. If I try this with Emacs,

git show BranchB:path/to/file | emacs -

an empty Emacs buffer opens with a message "Unknown option '-'" in the minibuffer.

I know that I can send the output of git show to a file and then open that file in Emacs, but I'm looking for a more streamlined workflow that I expect exists.

How can I open a file from another Git branch directly in Emacs?

Borea Deitz
  • 379
  • 4
  • 11

1 Answers1

2

This is a cross-site duplicate of superuser's How to make Emacs read buffer from stdin on start?. The answer there works here:

emacs --insert <(git show BranchB:path/to/file)
amalloy
  • 89,153
  • 8
  • 140
  • 205
  • I wouldn't have thought to search for that phrasing on my own, but this is correct. For this method, Emacs does not apply the syntax color-coding for a recognized file type, but I can work on that separately. Thanks! – Borea Deitz Oct 07 '21 at 20:16