如何在 Emacs 中打开来自另一个 Git 分支的文件?

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

BranchA 工作,我经常需要参考 BranchB 中的文件。 git show BranchB:path/to/file 命令会将 file 的内容转储到终端,但这很难阅读和导航。我想在 Emacs window.

中打开 BranchB:path/to/file

this answer 上的最高评论表明我可以用 git show branch:file | vim - 的 vim 做到这一点。如果我用 Emacs 试试这个,

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

打开一个空的 Emacs 缓冲区,并在迷你缓冲区中显示一条消息“未知选项‘-’”。

我知道我可以将 git show 的输出发送到一个文件,然后在 Emacs 中打开该文件,但我正在寻找我期望存在的更简化的工作流程。

如何在 Emacs 中直接从另一个 Git 分支打开文件?

这是超级用户 How to make Emacs read buffer from stdin on start? 的跨站点副本。那里的答案在这里有效:

emacs --insert <(git show BranchB:path/to/file)