是否有可能针对标准输入对文件进行git-diff? [英] Is it possible to git-diff a file against standard input?

查看:78
本文介绍了是否有可能针对标准输入对文件进行git-diff?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我正在编辑一个文件。如果我保存该文件, git-diff 会给我它相对于索引的改变。我希望在不保存文件的情况下获得相对于索引的更改 - 对于实时差异。



一种解决方案是将未保存的更改写入临时文件(即将文件保存到别处),将暂存文件写入另一个临时文件( git show:file> tempfile2 ),然后 git-diff tempfile tempfile2 。然而,这似乎不雅。



有没有更好的方法?

解决方案

改进Ash Berlin的答案。



这可以让你使用git-diff的漂亮功能。

  git show:file | git diff --no-index  -   -  temp_saved_pa​​th 

请注意,这仍然可能不如你会喜欢,因为你仍然需要写入临时文件。在保存文件之前,所做的更改要么不在磁盘上(仅在内存中),要么在某种类型的临时文件中,这些文件是依赖于编辑器的。 Vim可能可以一步完成这项工作,但我还不够熟悉。


Let's say I'm editing a file. If I save the file, git-diff will give me its changes relative to the index. I'd like to get the changes relative to the index without saving the file first – for a "realtime" diff.

One solution is to write the unsaved changes to a temporary file (i.e. save the file elsewhere), write the staged file to another temporary file (git show :file > tempfile2) then git-diff tempfile tempfile2. However that seems inelegant.

Is there a better way?

解决方案

Improving upon Ash Berlin's answer.

This allows you to use the nice features of git-diff.

git show :file | git diff --no-index -- - temp_saved_path

Note that this still might not be as convenient as you'd like, because you still have to write to a temp file. Until you save the file, the changes are either not on disk at all (in-memory only), or in some kind of temporary file that is editor-dependent. It's possible that Vim could do this seamlessly in one step, but I'm not familiar enough to say.

这篇关于是否有可能针对标准输入对文件进行git-diff?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆