如何使用 git 比较两个不在 repo 中的文件 [英] How to compare two files not in repo using git

查看:15
本文介绍了如何使用 git 比较两个不在 repo 中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'd like to compare two css files which are not in any git repository. Is there such a functionality in git?

推荐答案

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

git's diff is more functional than the standard unix diff. I often want to do this and since this question ranks highly on google, I want this answer to show up.

这个问题:如何使用<代码>git diff --color-words 在 Git 存储库之外?

This question: How to use git diff --color-words outside a Git repository?

展示了如何使用 git 来比较文件,其中至少一个文件不在存储库中,使用 --no-index:

Shows how to use git to diff files where at least one of them is not in the repository by using --no-index:

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

git 跟踪哪个和哪个不跟踪都没有关系 - 一个或两个都可以不被跟踪,例如:

It doesn't matter which one is tracked by git and which is not - one or both can be untracked, eg:

$ 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

此处无法显示颜色,因此我在示例中用竖线分隔更改.

The color can't be shown here so I separated the changes with a pipe in the example.

这篇关于如何使用 git 比较两个不在 repo 中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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