O'Reilly logo

Version Control with Git by Jon Loeliger

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required