我如何配置git忽略本地的一些文件? [英] How do I configure git to ignore some files locally?
问题描述
我可以忽略本地文件而不污染其他人的全局git配置吗?我在我的git状态下有未跟踪的垃圾邮件文件,但我不想为我在本地分支机构中每一个随机的未跟踪文件提交git config更改。
解决方案从相关的Git文档:
特定于特定存储库但不需要与其他相关存储库共享的模式(例如,存储在存储库内的辅助文件,但是特定于一个用户的工作流)应该放入
$ GIT_DIR / info / exclude
文件中。
.git / info / exclude
文件具有与任何 .gitignore
文件相同的格式。另一个选择是将 core.excludesFile
设置为包含全局模式的文件的名称。
请注意,如果您已经有了暂时的更改,您必须在编辑您的忽略模式后运行以下命令:
git update-index --assume-unchanged [ < file> ...]
$ GIT_DIR
:这是全部使用的记法 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.
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 [<file>...]
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忽略本地的一些文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!