如何在不使用.gitignore的情况下让Git忽略文件? [英] How do you make Git ignore files without using .gitignore?
问题描述
到 gitignore ,在Git考虑的不同忽略模式来源中有一个优先顺序:
$ GIT_DIR / info / exclude
读取的模式。
core.excludesfile
。
最后两个可以是您的问题的解决方案,但:
- 它们不会被复制到远程存储库
- 它们可以让他们的模式被其他来源重写
(另见 SO问题)
另外两个解决方案涉及更新索引( git update-index
):
-
git update-index --assume-unchanged
:参见 Git:仅在本地回购中找到一个文件并且将其保存在远程仓库 。
这是以利亚林在评论。
- 您甚至可以忽略文件夹内容:
git update-index --assume-unchanged
目录。 使用- no-assume-unchange
来撤消效果:请参阅是否可以通过assume-unchanged
来保护git add
文件? 。
- 您甚至可以忽略文件夹内容:
但是,当您签出另一个分支或何时你 git pull
,那么忽略状态可能会被重置。因此,另一个选项:
$ b $ ul
git update-index --skip-worktree
;请参阅:在 Git - 假定 - 不变
'和'<$之间的区别c $ c> skip-worktree '。
Due to external weird constraints I cannot modify the .gitignore of my repository. Is there a way to ignore files and directories other than modifying a .gitignore? Even if it is a global solution like a global configuration that will be applied to all my repositories.
Do not forget, according to gitignore, that there is an order of precedence in the different "ignore pattern sources" that Git consider:
- Patterns read from the command line for those commands that support them.
- Patterns read from a .gitignore file in the same directory as the path, or in any parent directory, with patterns in the higher level files (up to the root) being overridden by those in lower level files down to the directory containing the file.
- Patterns read from
$GIT_DIR/info/exclude
. - Patterns read from the file specified by the configuration variable
core.excludesfile
.
The last two can be a solution for your problem but:
- they are not replicated for a distant repository
- they can have their patterns overridden by the other sources
(See also this SO question)
The other two solutions involve updating the index (git update-index
):
git update-index --assume-unchanged
: see "Git: untrack a file in local repo only and keep it in the remote repo".
It is mentioned by Elijah Lynn in the comments.- You can even ignore a folder content: "
git update-index --assume-unchanged
on directory". - Use
--no-assume-unchange
to reverse the effect: See "Is it possible togit add
a file currently protected byassume-unchanged
?".
- You can even ignore a folder content: "
However, when you checkout another branch or when you git pull
, that "ignore" status might be reset. Hence the other option:
git update-index --skip-worktree
; see:
The difference between the two is explained in "Git - Difference Between 'assume-unchanged
' and 'skip-worktree
'".
这篇关于如何在不使用.gitignore的情况下让Git忽略文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!