Want to exclude file from “git diff”

后端 未结 13 1941
梦谈多话
梦谈多话 2020-12-07 07:27

I am trying to exclude a file (db/irrelevant.php) from a Git diff. I have tried putting a file in the db subdirectory called .gitattributes

13条回答
  •  再見小時候
    2020-12-07 07:35

    Relative to the git root directory

    git diff accepts an optional exclude

    git diff -- ":(exclude)thingToExclude"
    

    You might want to add some wild cards

    git diff -- ":(exclude)*/thingToExclude/*"
    

    Target specific file types

    git diff -- ":(exclude)*/$1/*.png"
    

    Or drop a little script for your dotfiles

    Such as .bash_profile or .zshrc

    gde() {
        # git diff exclude files or folders 
        # usage: 
        # gde fileOrFolderNameToExclude
        git diff -- ":(exclude)*/$1/*"
    }
    

提交回复
热议问题