How do I configure git to ignore some files locally?

前端 未结 11 1110
深忆病人
深忆病人 2020-11-22 01:03

Can I ignore files locally without polluting the global git config for everyone else? I have untracked files that are spam in my git status but I don\'t want to commit git c

11条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-22 01:31

    From the relevant Git documentation:

    Patterns which are specific to a particular repository but which do not need to be shared with other related repositories (e.g., auxiliary files that live inside the repository but are specific to one user's workflow) should go into the $GIT_DIR/info/exclude file.

    The .git/info/exclude file has the same format as any .gitignore file. Another option is to set core.excludesFile to the name of a file containing global patterns.

    Note, if you already have unstaged changes you must run the following after editing your ignore-patterns:

    git update-index --assume-unchanged 
    

    Note on $GIT_DIR: This is a notation used all over the git manual simply to indicate the path to the git repository. If the environment variable is set, then it will override the location of whichever repo you're in, which probably isn't what you want.


    Edit: Another way is to use:

    git update-index --skip-worktree 
    

    Reverse it by:

    git update-index --no-skip-worktree 
    

提交回复
热议问题