git diff branch –name-status –ignore

Is there a way to ignore a path(s) when doing git diff?

such as git diff branch –name-status –ignore=this/path

  • Git Bash & Pageant not using keys
  • Git error: refname 'HEAD' is ambiguous
  • Reasons why git is not visible to Rstudio (OSX)
  • Git Annex with GitHub?
  • How to find the files that changed more than X times in a git repo?
  • Visual Studio Code push automatically
  • Git: pathspec 'path' did not match any file(s) known to git
  • Troubleshooting misplaced .git directory (nothing to commit)
  • Travis-ci can not build github commit made by other github repository contributors
  • Heroku deleting files upon git push?
  • gems error on windows - “openpath: pathname too long”
  • Swap git submodule with own fork
  • 3 Solutions collect form web for “git diff branch –name-status –ignore”

    This is a bit of a hack but you could do this.

    git diff banch --name-status | grep -v this/path

    Not entirely git, but does the job.

    As they ~say here: Exclude a directory from git diff, you can use something like this:

    git diff --name-only $branch_name | grep -v -E "$excluding" | xargs git diff $branch_name --

    …where branch_name is the other branch and excluding is the pattern you’d like to exclude. I’m not sure if git-diff will eventually provide a parameter for something like that, and I didn’t find such an option in the git documentation, so this command is what I use for now.

    The only caveat is that you have to be at the top level of your working directory (i.e., the same folder that contains your .git folder) for this command to work, since the paths you pass in to git diff -- at the end via xargs are relative to that.

    You can make a script out of this to do the work for you in your favorite shell, e.g.

    if [[ $# < 2 ]] ; then
        echo "Usage: \n   gdx [git-diff-params] branch_name extended_reg_exp\n"
        echo "\nExamples:\n   gdx development jpg \n   gdx --name-only master origin/master jar \n   gdx development '[a-zA-Z]+'"
        exit 1
    ## Get a list of all the paths to include
    git_paths=$(git diff --name-only $branch_name | grep -v -E "$excluding")
    if [[ ${#git_paths} = 0 ]] ; then
        #no diffs
        exit 0
        ## Escape special characters
        for i in {1..${#git_paths}}
        ## Run the diff
        eval "git diff ${=diff_options} $branch_name -- $git_paths"

    This takes arguments and prints usage and whatnot. I use it like so:

    gdx HEAD^ "*.jar"

    You can add the paths you don’t care about to your .gitignore file.

    EDIT: You can use git diff files/you/care/about to see the diffs you are interested in.

    For example, if git status shows that a bunch of files are changed:

    modified: foo/bar
    modified: foo/baz
    modified: some/more/stuff
    modified: and/some/more

    you can use git diff foo to just look at the changes in the foo directory, or git diff some/more/stuff and/some/more to look at everything except foo.

    This will be fine if you want to look at the diffs for a few files, but won’t work so well if you want to look at everything except one or two files. I don’t think there’s a way to tell git diff to use a negation of the files you specify.

    Another alternative would be to use git add --interactive, but it’s probably a bit cumbersome for what you’re doing.

    It also turns out that .gitignore doesn’t ignore files that are already under version control, so that idea was never going to work. Forget I mentioned it. 🙁

    Git Baby is a git and github fan, let's start git clone.