如何配置 git 以忽略本地的某些文件? [英] How do I configure git to ignore some files locally?
问题描述
我可以在不污染其他人的全局 git 配置的情况下忽略本地文件吗?我的 git 状态中有垃圾邮件的未跟踪文件,但我不想为本地分支中的每个小随机未跟踪文件提交 git 配置更改.
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 config changes for every single little random untracked file I have in my local branches.
推荐答案
来自 相关 Git 文档:
特定于特定存储库但不需要与其他相关存储库共享的模式(例如,位于存储库内但特定于一个用户的工作流的辅助文件)应进入 $GIT_DIR/info/exclude
文件.
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.
.git/info/exclude
文件与任何 .gitignore
文件具有相同的格式.另一种选择是将 core.excludesFile
设置为包含全局模式的文件的名称.
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 <file-list>
关于 $GIT_DIR
的注释:这是一个使用的符号 全部 git 手册只是为了指明git 存储库的路径.如果设置了环境变量,那么它将覆盖您所在的任何存储库的位置,这可能不是您想要的.
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.
编辑:另一种方法是使用:
git update-index --skip-worktree <file-list>
反转:
git update-index --no-skip-worktree <file-list>
这篇关于如何配置 git 以忽略本地的某些文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!