git 在编辑器中显示旧版本的文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18148067/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
git show old version of file in editor
提问by kodu
I figured out I can show old versions of a file using 'git log filename' to show the commits, and then use 'git show commit-id:filename' for the old version. But it just puts it in less.
我发现我可以使用 'git log filename' 显示文件的旧版本来显示提交,然后使用 'git show commit-id:filename' 来显示旧版本。但它只是把它放在更少的地方。
I would like to be able to view this in emacs, so I can navigate as I'm used to and so that there is syntax highlighting. I found out I can't set the git core.pager to emacs since emacs cannot read from stdin.
我希望能够在 emacs 中查看它,这样我就可以按照我习惯的方式进行导航,这样就可以突出显示语法。我发现我无法将 git core.pager 设置为 emacs,因为 emacs 无法从 stdin 读取。
Does anyone know how I could do this? Or do you have another good way of checking old versions of files?
有谁知道我怎么能做到这一点?或者你有另一种检查旧版本文件的好方法吗?
回答by Schleis
Just use >
and put it into a file that you can open in emacs.
只需使用>
并将其放入您可以在 emacs 中打开的文件中即可。
git show commit-id:filename > oldfile
Then open the file in emacs.
然后在emacs中打开文件。
回答by Nimlar
If you are using bash
, you can use Process Substitution.
如果您正在使用bash
,则可以使用进程替换。
gvim <(git show commit-id:filename)
回答by Peter
Emacs package git-timemachine lets you step back and forth through git revisions of a file:
Emacs 包 git-timemachine 允许您来回遍历文件的 git 修订版:
回答by Sam Arthur Gillam
Using the following Vim command, one can view a previous version of a file without having to cleanup anything afterward.
使用以下 Vim 命令,您可以查看文件的先前版本,而无需事后清理任何内容。
git show commit-id:filename | vim - -n
Explanation: The dash argument of the vim command makes vim load whatever comes in from standard input. The -n option suppresses the creation of swap files.
说明:vim 命令的 dash 参数使 vim 加载来自标准输入的任何内容。-n 选项禁止创建交换文件。