Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CVS style diffs in git

Tags:

git

cvs

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?

like image 266
user1207217 Avatar asked Jan 17 '26 03:01

user1207217


1 Answers

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.)

like image 120
Keith Thompson Avatar answered Jan 19 '26 18:01

Keith Thompson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!