Search code examples
gitgit-diffgit-config

How to disable pager in git only for diff with name-only option?


I need git diff using a pager while git diff --name-only not.

Have tried git config --global pager.diff.name-only false and not working.

The desired behavior is like git --no-pager diff --name-only. But I don't want to type --no-pager every time.

Is there any config or alias could do this?


Solution

  • You can make an alias:

    [alias]
        ndiff = !git --no-pager diff --name-only
    

    and then run git ndiff instead of git diff --name-only. Or, leave the --no-pager part out of the alias and run git ndiff --name-only, with ndiff standing for no-pager-diff.

    Or, instead of git diff, you can run git diff-tree or git diff-files or git diff-index. These three commands are the plumbing command back-ends that git diff uses for (most of) its various modes of operation. None of these use a pager, and most of them require additional options (e.g., -r) to be used the same way git diff would run them, but they do exist and are the right way to write scripts. For your own aliases, there is no need to use the plumbing commands; your own alias can just invoke git --no-pager diff <options>.