How can I limit git-diff to one directory only, without its children?

git diff between commits
git diff between branches
git diff example
git diff specific file
git log
git diff file
git diff two files
git diff-tree

I'm using git diff --name-status to track which files have been modified/added/removed/renamed/copied between two commits, and it works great.

Now suppose I move file file1 to newdir/file1, commit, and then run git diff, I get this:

$ git diff --name-status -C HEAD~1 HEAD
R100    file1    newdir/file1

Is there a way to ask git to limit itself to the list of changes inside a given directory but not its children? I'd like to know the exact changes both for the root directory and for the newdirdirectory, separately. For newdir, it's easy:

$ git diff --name-status -C HEAD~1 HEAD -- newdir
A       newdir/file1

… but how can I obtain the "complementary" diff info in the root directory? I.e., this output:

$ git diff ???
D       file1

Note that I want to keep the -C option to detect renames and copies inside the same directory.

Pass it through to grep:

git diff --name-status HEAD..HEAD~1 . | grep ^[^/]*$

This will filter out anything that contains a sub directory, if you need to get something from a deeper do this:

git diff --name-status HEAD..HEAD~1 <path> | grep ^<path>[^/]*$

You could easily alias this if you wanted to.

git-diff Documentation, However, "diff" is about comparing two endpoints, not ranges, and the range notations ("<commit>. By giving a third parameter <count> , you can limit the output to the first <count> Output only the last line of the --stat format containing total number of Count changes in a child directory for the parent directory as well. As you can see in this TOML screenshot, on the left, git-diff colors the changes since last commit: (Notably, I added lines (green) and also modified sensitive content (yellow) to display it on this issue) Now for .md files, the git-diff info cannot be seen, even though git-diff "Move to Next Diff" command still works.

I know its probably doable in git, but I would be tempted to use the filterdiff/grepdiff programs from patchutils something like this should work ok

git diff -C .... | filterdiff --clean -x '*/*/**'

git-diff-tree Documentation, git diff-tree [--stdin] [-m] [-s] [-v] [--no-commit-id] [--pretty] [-t] [-r] [-c | --cc] If there is only one <tree-ish> given, the commit is compared with its parents (see --stdin below). By giving a third parameter <count> , you can limit the output to the first <count> Count changes in a child directory for the parent directory as well. Note that without --full-history, this still simplifies merges: if one of the parents is TREESAME, we follow only that one, so the other sides of the merge are never walked. --simplify-merges First, build a history graph in the same way that --full-history with parent rewriting does (see above).

If running a Linux or compatible shell with find available, you can use find to generate the list of non-directory files in the current (or other) directory, then feed that to git diff, e.g.:

git diff --stat --other-git-diff-args -- $(find . -type f -depth 1 -print0 | tr '\0' ' ')

Git - git-diff Documentation, By giving a third parameter <count> , you can limit the output to the first <count> lines, Count changes in a child directory for the parent directory as well. When --raw , --numstat , --name-only or --name-status has been given, do not munge� When "git-diff-index", "git-diff-tree", or "git-diff-files" are run with a -p option, "git diff" without the --raw option, or "git log" with the "-p" option, they do not produce the output described above; instead they produce a patch file. You can customize the creation of such patches via the GIT_EXTERNAL_DIFF and the GIT_DIFF_OPTS

git-diff - Show changes between commits, commit , git diff [options] <blob> <blob> git diff [options] [--no-index] [--] <path> <path> By giving a third parameter <count> , you can limit the output to the first <count> lines, Output only the last line of the --stat format containing total number of modified files, Count changes in a child directory for the parent directory as well. It is a rounded down integer, followed by a percent sign. The similarity index value of 100% is thus reserved for two equal files, while 100% dissimilarity means that no line from the old file made it into the new one. Combined Diff Format "git-diff-tree", "git-diff-files" and "git-diff" can take -c or --cc option to produce combined diff.

git-diff(1), --staged is a synonym of --cached. git diff [--options] <commit> [--] [<path>. However, "diff" is about comparing two endpoints, not ranges, and the range -- shortstat Output only the last line of the --stat format containing total number of at all. cumulative Count changes in a child directory for the parent directory as well. List only filenames (instead of the "long" output), one per line.--abbrev[=<n>] Instead of showing the full 40-byte hexadecimal object lines, show only a partial prefix. Non default number of digits can be specified with --abbrev=<n>.--full-name . Instead of showing the path names relative to the current working directory, show the full path names.

git-log(1): commit logs, If HEAD does not exist (e.g. unborned branches) and <commit> is not The third form (git diff <commit> <commit>) can also be used to compare two <blob> objects. Output only the last line of the --stat format containing total number of Count changes in a child directory for the parent directory as well. You can limit git log’s output by including the -<n> option. For example, the following command will display only the 3 most recent commits. git log -3 By Date. If you’re looking for a commit from a specific time frame, you can use the --after or --before flags for filtering commits by date. These both accept a variety of date formats as a

Comments
  • git diff <branchA>..<branchB> -- <path> worked for me.
  • The output of git diff --name-status is not a patch file, but a list of modified files only, so it seems like filterdiff does not help.