git 使用 .gitignore 不提交 bin、debug 和 config 文件夹

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13658211/
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-19 07:50:12  来源:igfitidea点击:

Using .gitignore to not commit bin, debug and config folders

gitgitignore

提问by Mortalus

I'm using git in my ASP.NET MVC project.

我在我的 ASP.NET MVC 项目中使用 git。

I want no files from debug, binor configfolder to show in the “Pending Chages” dialog so I will not have to commit them to my repository.

我不希望debug,binconfig文件夹中的文件显示在“Pending Chages”对话框中,因此我不必将它们提交到我的存储库。

These files are machine specific specially the config folder.

这些文件是机器特定的,特别是 config 文件夹。

I tried to add the following to .gitignore:

我尝试将以下内容添加到.gitignore

myproject\bin**
myproject\obj**
myproject\config\**

This did not work because all files under all three folders are still displayed after each build or config changes.

这不起作用,因为在每次构建或配置更改后,所有三个文件夹下的所有文件仍会显示。

What am I doing wrong?

我究竟做错了什么?

回答by mcalex

Remove the ** from the dir name (also, I use forward slashes, don't know if that makes a difference).

从目录名称中删除 ** (另外,我使用正斜杠,不知道这是否有区别)。

Remember to remove all the offending files that might be in your repository already. A delete and commit should take care of it.

请记住删除可能已经在您的存储库中的所有有问题的文件。删除和提交应该处理它。

Also, if you have multiple projects you can get all bins ignored by not putting the project name in front. This should work:

此外,如果您有多个项目,则可以bin通过不将项目名称放在前面来忽略所有s。这应该有效:

bin
obj
config

This looks like the definitive SO answer: How do I ignore files in a directory in Git?

这看起来像明确的 SO 答案: 如何忽略 Git 目录中的文件?