For "git diff" is there a -U<infinity> option to show the whole file?

If you just use a large number with -U, you could choose the large number to be the point at which your application can't handle displaying such a large file (diff).

it's a correctness issue if my file is larger than 1M lines

And to address this issue, you can check the output for more than one @@ ... @@ line to determine whether it's complete — this allows you to avoid silently giving a wrong number.


Frankly, the best option is to use git difftool rather than vanilla git diff. To see which tools your version of git supports, enter

git difftool --tool-help

which, with my version (2.3.0), shows the following

$ git difftool --tool-help
'git difftool --tool=<tool>' may be set to one of the following:
        araxis
        gvimdiff
        gvimdiff2
        gvimdiff3
        meld
        vimdiff
        vimdiff2
        vimdiff3

The following tools are valid, but not currently available:
        bc
        bc3
        codecompare
        deltawalker
        diffmerge
        diffuse
        ecmerge
        emerge
        kdiff3
        kompare
        opendiff
        p4merge
        tkdiff
        xxdiff

I usually use meld, but that's just a personal preference. git difftool takes the same arguments as git diff plus a few to help with the process (I find -y useful to prevent the prompts when moving from one file to the next).

To check out the changes introduced by a specific commit, for example, you can use

git difftool -y -t meld 08f0f82^..08f0f82

obviously replacing 08f0f82 with the correct SHA-1.

My biggest complaint is that it launches the tool for each modified file in sequence (hence specifying the -y option).

If you only wanted to examine the changes to a particular file in that commit, you can just add the filename to the command line.

git difftool -y -t meld 08f0f82^..08f0f82 myfile.c

Obviously, this is for interactive use - not for scripting

Tags:

Git