.net 我怎么能忽略 git 存储库中的 bin 和 obj 文件夹?

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

How could I ignore bin and obj folders from git repository?

.netgitgitignore

提问by chester89

I want to ignore bin and obj folders from my git repository. As I've found out, there is no easy way to do this in .gitignore. So, are there any other way? Using clean solution in Visual Studio?

我想从我的 git 存储库中忽略 bin 和 obj 文件夹。正如我发现的那样,在 .gitignore 中没有简单的方法可以做到这一点。那么,还有其他办法吗?在 Visual Studio 中使用干净的解决方案?

回答by Tim Robinson

I'm not sure why this doesn't work for you. In case it helps, here's a typical .gitignore file from one of my Visual Studio/git projects:

我不确定为什么这对你不起作用。如果有帮助,这里有一个来自我的 Visual Studio/git 项目的典型 .gitignore 文件:

*.suo
*.user
_ReSharper.*
bin
obj
packages

回答by Arvind Krmar

simply making an entry in gitignore may not ignore files, you may need to commit it. I used the following method and worked for me

简单地在 gitignore 中创建一个条目可能不会忽略文件,您可能需要提交它。我使用了以下方法并对我来说有效

git rm -r --cached .

git add .

then

然后

git commit -am "Remove ignored files"

However, this ignores my scripts folder which I included later into the repository.

但是,这会忽略我稍后包含在存储库中的脚本文件夹。

回答by Nilay

If you are using Visual Studio then there is a simple way to do this.

如果您使用的是 Visual Studio,那么有一种简单的方法可以做到这一点。

  1. Open Team Explorer
  2. Click on settings
  3. Repository Settings
  4. Under Ignore & Attribute file section Click on Add beside Ignore file.
  1. 打开团队资源管理器
  2. 点击设置
  3. 存储库设置
  4. 在忽略和属性文件部分下单击忽略文件旁边的添加。

It will create a default .gitignore file, which will ignore most of common folders & files that will used by framework/language.

它将创建一个默认的 .gitignore 文件,该文件将忽略框架/语言将使用的大多数常见文件夹和文件。

enter image description here

在此处输入图片说明

回答by user151019

If you want to ignore bin and obj in ALL your projects then you can use (from gitignore man page)

如果您想在所有项目中忽略 bin 和 obj,则可以使用(来自gitignore 手册页

Patterns read from the file specified by the configuration variable core.excludesfile.

从配置变量 core.excludesfile 指定的文件中读取的模式。

core.excludesfile can be set in a config file which is ~/.gitconfig in Unix - I don't know where it is under Windows

core.excludesfile 可以在 Unix 中的 ~/.gitconfig 配置文件中设置 - 我不知道它在 Windows 下的位置

回答by Denys Wessels

  • Locate the binand objfolders in Windows Explorer
  • Right click TortoiseGit > Delete and add to ignore list > bin
  • Right click TortoiseGit > Delete and add to ignore list > obj
  • 在 Windows 资源管理器中找到binobj文件夹
  • 右键单击 TortoiseGit > 删除并添加到忽略列表 > bin
  • 右键单击 TortoiseGit > 删除并添加到忽略列表 > obj

回答by makdu

If you try through source tree and still the ignore files are not coming in , go to tools-->option->Git and then select location of the .gitignore enter image description here

如果您尝试通过源代码树并且仍然没有忽略文件,请转到工具-->选项-> Git,然后选择 .gitignore 的位置 在此处输入图片说明

回答by Raphael Pinel

If you have committed the bin and obj folders previously, adding them to .gitignore will not automatically delete them. You need to commit deleting these folders with for example git rm -rf objor git rm -rf yourProject/objthen commit the deletion

如果之前已经提交了 bin 和 obj 文件夹,将它们添加到 .gitignore 不会自动删除它们。您需要提交删除这些文件夹,例如 git rm -rf objgit rm -rf yourProject/obj然后提交删除

回答by pk_code

In my case, bin and obj folders were nested under Project folder from the root .gitignore file, so I had to add it like below:

就我而言,bin 和 obj 文件夹嵌套在根 .gitignore 文件的 Project 文件夹下,所以我必须像下面这样添加它:

[PROJECT_FOLDER_NAME]/bin
[PROJECT_FOLDER_NAME]/obj

[PROJECT_FOLDER_NAME]/bin
[PROJECT_FOLDER_NAME]/obj

Replace PROJECT_FOLDER_NAME with your project folder name

将 PROJECT_FOLDER_NAME 替换为您的项目文件夹名称