git diff with Path Limiting

By default, the command git diff operates on the entire directory structure rooted at a given tree object. However, you can leverage the same path limiting technique employed by git log to limit the output of git diff to a subset of the repository.

For example, at one point[18] in the development of the Git’s own repository, git diff --stat displayed this:

$ git diff --stat master~5 master
 Documentation/git-add.txt            |    2 +-
 Documentation/git-cherry.txt         |    6 +++++
 Documentation/git-commit-tree.txt    |    2 +-
 Documentation/git-format-patch.txt   |    2 +-
 Documentation/git-gc.txt             |    2 +-
 Documentation/git-gui.txt            |    4 +-
 Documentation/git-ls-files.txt       |    2 +-
 Documentation/git-pack-objects.txt   |    2 +-
 Documentation/git-pack-redundant.txt |    2 +-
 Documentation/git-prune-packed.txt   |    2 +-
 Documentation/git-prune.txt          |    2 +-
 Documentation/git-read-tree.txt      |    2 +-
 Documentation/git-remote.txt         |    2 +-
 Documentation/git-repack.txt         |    2 +-
 Documentation/git-rm.txt             |    2 +-
 Documentation/git-status.txt         |    2 +-
 Documentation/git-update-index.txt   |    2 +-
 Documentation/git-var.txt            |    2 +-
 Documentation/gitk.txt               |    2 +-
 builtin-checkout.c                   |    7 ++++-
 builtin-fetch.c                      |    6 ++--
 git-bisect.sh                        |   29 ++++++++++++--------------
 t/t5518-fetch-exit-status.sh         |   37 ++++++++++++++++++++++++++++++++++
 23 files changed, 83 insertions(+), 40 deletions(-)

To limit the output to just Documentation changes, you could instead use git diff --stat master~5 master Documentation:

$ git diff --stat master~5 master Documentation ...

Get Version Control with Git now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.