Search code examples
gitdiffgit-diff

How do I look at the git differences from another branch, for only the currently-modified files?


Often when I'm baselining tests, I want to see what's changed in the test products relative to the merge parent, but at that time I don't want to look at all differences. (I.e., I don't want to see code, or tests I've already worked through in earlier changesets on my branch.)

How do I narrow the diff to just the files that are currently modified?


Solution

  • One option is to do

    git diff <branch> -- $(git diff --name-only)
    

    This has the limitation that you have to run it in the root directory for the path to be interpreted correctly.

    If you don't want that limitation you can use sed and xargs

    git diff --name-only HEAD | sed 's/^/:\/:/' | xargs git diff <branch-or-commit> --