10

when I try to run

diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c

I get unknown option (I have installed git via apt-get install git)

3 Answers 3

18

Either use

diff -u file1 file2

or

git diff branch/commit1 branch/commit2

More on git diff at https://www.kernel.org/pub/software/scm/git/docs/git-diff.html

I am not aware of any --git option however for diff and the man page doesn't show it.

4

Generally speaking, when you run a recursive diff between two directories, for each file diff includes a diff command showing you what it is doing for each file. For example:

$ diff -ru a b
diff -ru a/file b/file
--- a/file  2015-07-17 01:06:14.078875805 -0700
+++ b/file  2015-07-17 01:06:21.969077076 -0700
@@ -1 +1 @@
-hello
+goodbye

Git wants to produce patches in the same format, so each file must be preceded by a line starting "diff...". But since git is using it's own internal diff implementation, to make it clear to people reading the output what they are looking at, git adds the imaginary flag --git.

In reality, if you want to use git to diff two files or directories in the file system, you can run:

git diff --no-index a b

(The --no-index flag says to ignore any git repository you are in. That option can be omitted if you are not in a git repository.) Git produces output in the "unidiff" format. If you want to approximate that with the system diff command, you can use diff -ru a b. (The -u flag selects unidiff format, while the -r recurses into directories.)

2

The real truth is that git is displaying a fake command.

$ git diff drivers/cpufreq/intel_pstate.c
diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
index 286bfoo..14a8foo 100644
--- a/drivers/cpufreq/intel_pstate.c
+++ b/drivers/cpufreq/intel_pstate.c

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .