如何告诉 Git 仅忽略存储库顶级中的特定文件名?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6168736/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 11:01:54  来源:igfitidea点击:

How do I tell Git to ignore a specific filename only in the repository's top level?

gitgitignore

提问by PleaseStand

Possible Duplicate:
How to exclude file only from root folder in GIT

可能的重复:
如何仅从 GIT 中的根文件夹中排除文件

For a specific JavaScript project, I am using the TinyWeb HTTP Serverfor local testing (to work around a specific security limitation that applies to file URLs). That program requires I have an index.htmlfile in the root directory, but I do not want to commit that file to my Git repository.

对于特定的 JavaScript 项目,我使用TinyWeb HTTP Server进行本地测试(以解决适用于文件 URL 的特定安全限制)。该程序要求我index.html在根目录中有一个文件,但我不想将该文件提交到我的 Git 存储库。

How can I stop Git from bugging me about this "untracked file" on every commit? I do want to commit all index.htmlfiles located in subdirectories.

我怎样才能阻止 Git 在每次提交时就这个“未跟踪的文件”来烦我?我确实想提交index.html位于子目录中的所有文件。

回答by poke

Add this to your .gitignore(in the root folder):

将此添加到您的.gitignore(在根文件夹中):

/index.html

The leading /makes git use an absolute path (relative to the current .gitignorelocation), whereas all other lines are just treated as some kind of wildcard.

前导/使 git 使用绝对路径(相对于当前.gitignore位置),而所有其他行都被视为某种通配符。