2

Is there any way to make the output format of git diffs like cvs style diffs? I find git diffs to be less readable. Also, the git diffs appearing in more are annoying - how can I disable this?

Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
user1207217
  • 547
  • 1
  • 4
  • 15

3 Answers3

7

git diff uses the "universal" format, diff -u, by default. cvs diff uses the older standard diff format (deleted lines marked with <, added lines marked with >, no context around each difference).

You can get a "context diff" using git diff -c, or git diff -C5, for example, to get 5 lines of context rather than the default 3.

diff --normal (at least if you're using GNU diffutils) will produce an old-style diff, but git diff doesn't seem to recognize the --normal option.

Personally, I find context diffs much more readable than old-style diffs, so I've never found the need to use old-style diffs with git diff. Try git diff -c (along with haggai_e's suggestion to disable the pager).

If you really want the old-style diffs (<, >, no context), there's probably a way to do it.

EDIT :

If git diff doesn't do what you want, you can extract copies of the revisions of the file and use whatever diff tool you like on them. My own get-versions tool can extract multiple versions of a file from git (or from RCS or CVS).

And here's another solution, though it's a bit more complicated. As an example, I've cloned the git repo for git itself. If I want to compare two successive versions of the top-level README file, I can do this:

$ diff --normal <(git show 779d7e93773a0dcf918dc77023511fdc68161bd8:README) \
                <(git show 71ce415dc088f19a0b8d6c8567dfdd6d851842b2:README)
24,26c24,25
< compatible with the GPLv2).
< It was originally written by Linus Torvalds with help of a group of
< hackers around the net. It is currently maintained by Junio C Hamano.
---
> compatible with the GPLv2). It was originally written by Linus
> Torvalds with help of a group of hackers around the net.
$ 

It would be easy enough to wrap this in a small script.

Note that the file path following the : (README in the above example) is relative to the root of the repository, not to the current directory. You can precede the name with ./ to make to make it relative to the current directory. (The latter might not work with some older versions of git.)

Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
  • I don't know what version of git this is pertinent to, but for "git version 1.7.7.6", git diff -c is not valid, but git diff -Un (n for number of context lines) works. git diff -U0 is almost giving me what I want, but I still don't like the appearance. This is all a matter of preference thing really, while you prefer context diffs, I don't as it is just a sanity check before commit thing for me. If I need context diffs I'm using meld. Cheers for the tip however. Again, I'd mark up if it would allow me to. – user1207217 Feb 20 '12 at 13:49
  • See http://stackoverflow.com/questions/11331582/how-to-make-git-diff-output-normal-diff-format-non-unified-non-context - here we can pass the --normal option. Cheers – user1207217 Jan 14 '13 at 23:55
  • @user1207217: I updated my answer (just before I read the link in the above comment). – Keith Thompson Jan 15 '13 at 00:03
5

You can disable the pager by setting core.pager to an empty string:

git config --global core.pager ''
haggai_e
  • 4,689
  • 1
  • 24
  • 37
1

Try playing with standard diff formatting:

git difftool -y -x "diff --unchanged-group-format='' --old-line-format='< %L' --new-line-format='> %L'"

This gives CVS-like newlines and oldlines, with no context, but it doesn't insert the extras between groups of different lines. Not quite sure how to achieve the rest, given I don't know the extent to which you would like CVS-like formatting.

man diff

For more information

Also see

git difftool -y -x "diff -n"

But I doubt this does what you want. If this does work for you, to make it work every time with git diff, see Configuring diff tool with .gitconfig?, which references http://jeetworks.com/node/90 in the accepted answer.

Community
  • 1
  • 1
  • This combined with http://stackoverflow.com/questions/11331582/how-to-make-git-diff-output-normal-diff-format-non-unified-non-context gives me what I want. Cheers – user1207217 Jan 14 '13 at 23:55