Search code examples
diffgitk

How to limit number of diff lines shown in gitk?


Looking for an option/workaround to limit the diff content (shown in the bottom panel) for any particular file (e.g. to first N lines only), as the patch/diff may be too big and causes the GUI to freeze. I did try the different options accepted by git diff, but don't see any way to pass them to gitk (unlike git-gui). Note that limiting the number of lines of context does not work since the diff will still be shown with zero context.


Solution

  • You will have to change gitk's source code. It's one big Tcl/Tk file you can edit directly or make a copy of. It's location may depend on your operating system. If you are on linux or macos it's probably /usr/bin/gitk or /usr/local/bin/gitk.

    Inside the procedure diffcmd, change this line:

    set cmd [concat | git diff-tree -r $flags $ids]

    You could add diff-tree arguments, or simply pipe the diff output to another program, like head:

    set cmd [concat | git diff-tree -r $flags $ids | head -n500]

    This applies to the complete diff, not just to one file.