domlao
domlao

Reputation: 16029

How to use to diff to C++ source files and ignore the line space and comments

I have to C++ source files and I want to see the difference between the two files. But I don't want to see the diff between the comments.

Please advise.

Many thanks.

Upvotes: 1

Views: 718

Answers (1)

johnsyweb
johnsyweb

Reputation: 141790

One way would be to use the pre-processor to remove the comments and pass this into diff using process substitution...

diff -uwB <(g++ -E left.cpp) <(g++ -E right.cpp)

Of course this will pull in files that you #include and expand your #define macros, too. If they haven't changed, this should be quite readable.

The switches I have passed to diff are:

-w  --ignore-all-space  Ignore all white space.
-B  --ignore-blank-lines  Ignore changes whose lines are all blank.
-u  -U NUM  --unified[=NUM]  Output NUM (default 3) lines of unified context.

Upvotes: 3

Related Questions