How to compare two files not in repo using git

GitCompareDiff

Git Problem Overview


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

Git Solutions


Solution 1 - Git

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.

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

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

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.

Solution 2 - Git

diff -u

will give similar unified context output to git's diff.

Solution 3 - Git

Just use the diff command:

diff file1.ext file2.ext

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionCedric ReichenbachView Question on Stackoverflow
Solution 1 - GitKyle BurtonView Answer on Stackoverflow
Solution 2 - GitjamesView Answer on Stackoverflow
Solution 3 - GitedwardmpView Answer on Stackoverflow