如何使用git比较不在repo中的两个文件

时间:2012-07-19 13:04:38

标签: git compare diff

我想比较两个不在任何git存储库中的css文件。 git中有这样的功能吗?

3 个答案:

答案 0 :(得分:146)

git的diff比标准的unix diff更具功能性。我经常想这样做,因为这个问题在谷歌上排名很高,我希望这个答案出现。

这个问题:How to use git diff --color-words outside a Git repository?

使用--no-index显示如何使用git来区分至少其中一个文件不在存储库中的文件:

git diff --no-index file1.txt file2.txt

git跟踪哪一个并不重要 - 一个或两个都可以不跟踪,例如:

$ date > x
$ sleep 2
$ date > y
$ git diff --color-words --no-index x y
diff --git a/x b/y
index 6b10c7c..70f036c 100644
--- a/x
+++ a/y
@@ -1 + 1 @@
Wed Jun 10 10:57:45|10:57:47 EDT 2013

此处无法显示颜色,因此我在示例中使用管道分隔了更改。

答案 1 :(得分:3)

diff -u

会给git'差异提供类似的统一上下文输出。

答案 2 :(得分:0)

只需使用diff命令:

diff file1.ext file2.ext