18

When I use 'svn diff' from the command line, it prints out the lines that have changed but also the 3 unchanged lines before and after for context. I much prefer seeing only the changed lines with no context. I haven't been able to determine any command line options that will let me make it behave this way. Standard 'diff' and 'cvs diff' do what I want by default. Surely 'svn diff' can do this but I'm missing something. Anyone know how?

4 Answers 4

20

After looking into the useful link given above by unwind, the short answer is that svn's built-in diff can't do what I want. You can tell it to use the standard external diff though and pass arg's to that to tell it that you want no context. I put the following alias in my .bashrc and all now works well if I use that instead:

alias svndiff='svn diff --diff-cmd=diff -x -U0'
Sign up to request clarification or add additional context in comments.

1 Comment

-x is the extension parameter for svn diff, it causes the token immediately following, here -U0, to be passed to the diff command specified with --diff-cmd, here diff.
7

The suggestion above still produces the context format, but with 0 lines of context. This is still not the traditional diff output from before subversion.

What works for me is: svn di --diff-cmd=diff -x --normal

The --normal option (in the diff that ships with OSX) gives the traditional format that some folks prefer.

Comments

3

You could pipe the results of 'svn diff' to grep and write a regular expression to get what you want. For example, try this:

svn diff | grep "^[+-\]"

The above command gets you all lines that begin with a '+' or a '-' or a '\'. (You need the '\' if you want to see differences such as "\ No newline at the end of the file".)

1 Comment

This works fine if you want only the changed lines. However, it fails to output correct information about line numbers. E.g. with 3 lines of context before/after, "@@ -21,7 +21,7 @@" says line 24 was changed. With no context you'd see "@@ -24,1 +24,1 @@"
2

This thread seems to come to the conclusion that you should use an external diff command in order to control the amount of context.

I prefer unified diffs, so my fingers always type

svn diff -x -u

Which implies that an external (GNU diff) command is used, I think.

1 Comment

Thanks for the useful link. Surprising to me that the built-in diff can't do what I want. Seems to me to violate the Unix principle of having the least output asked for. Using the -x -u commands gives me the same results as not. 'svn help diff' tell me that those are the defaults. Maybe you don't need to type the extra char's after all?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.