我如何忽略 git 存储库中的 bin 和 obj 文件夹?

发布于 2024-08-23 13:13:09 字数 110 浏览 5 评论 0原文

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

箜明 2024-08-30 13:13:09

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

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

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:

*.suo
*.user
_ReSharper.*
bin
obj
packages
子栖 2024-08-30 13:13:09

简单地在 gitignore 中输入一个条目可能不会忽略文件,您可能需要提交它。我使用了以下方法并为我工作

git rm -r --cached .

git add .

,但是

git commit -am "Remove ignored files"

,这会忽略我稍后将其包含到存储库中的脚本文件夹。

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

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.

风为裳 2024-08-30 13:13:09

更新

最近更新 Visual Studio 2019 后,以下选项不可用。
或者,您也可以从以下位置复制最新的 gitignore 内容。
https://raw.githubusercontent.com/github/gitignore/master/VisualStudio.gitignore

原始答案

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

  1. 打开团队资源管理器,
  2. 单击
  3. “设置存储库设置”
  4. “忽略和”下的 。属性文件部分
    单击“忽略文件”旁边的“添加”。

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

输入图像描述这里

Update

After a recent update of Visual Studio 2019, the below option was not available.
Alternatively, you can also copy the latest gitignore content from the below location.
https://raw.githubusercontent.com/github/gitignore/master/VisualStudio.gitignore

Original Answer

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

  1. Open Team Explorer
  2. Click on settings
  3. Repository Settings
  4. Under Ignore & Attribute file section
    Click on Add beside Ignore file.

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

enter image description here

那些过往 2024-08-30 13:13:09

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

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 obj or git rm -rf yourProject/obj
then commit the deletion

妄想挽回 2024-08-30 13:13:09

尝试添加不需要的文件夹的名称,git 永远不会从前面提到的根目录开始进行这些更改。这对我来说很有效,可以将这些文件夹名称添加到 .gitignore 中:

bin
obj
packages

Try adding the names of unwanted folders and git will never take those changes right from that root directory mentioned onward. This worked for me though to add these folder names into .gitignore:

bin
obj
packages
极致的悲 2024-08-30 13:13:09

我让一些新开发人员将他们的 OBJ 和 Bin 文件签入存储库。
尽管我有 gitignore 来排除这些文件,但它在我的本地存储库中不起作用。

我执行了以下操作来解决此问题:

  1. 从存储库中删除了 Bin 和 Obj 文件夹。
  2. 也从我的本地存储库中删除了 bin 和 obj 文件夹。
  3. 创建/更新 gitignore 并保存(如果尚未完成)

如果存储库中还有其他用户特定文件,例如:Visual studio 中的 .suo
完成上述操作后,您可以将它们添加到 gitignore 文件中。

我在浪费了一点时间后发现了这一点,希望这对处于同一场景的人有所帮助。

I have had some new developers check in their OBJ and Bin files to the repository.
Even though I have the git ignore to exclude those files it would not work in my local repo.

I did the following to fix this

  1. Deleted the Bin and Obj folders from the repository.
  2. Deleted bin and obj folders from my local repo as well.
  3. Created/Update the gitignore and save (If not done already)

If you have other user specific files also in the repo ex: .suo in Visual studio
you can add them to the gitignore file after doing the above.

I found this after wasting quiet a bit of time hope this helps some one in the same scenario.

空城缀染半城烟沙 2024-08-30 13:13:09
  • 在 Windows 资源管理器中找到 binobj 文件夹,
  • 右键单击 TortoiseGit >删除并添加到忽略列表> bin
  • 右键单击​​ TortoiseGit >删除并添加到忽略列表>对象
  • Locate the bin and obj folders in Windows Explorer
  • Right click TortoiseGit > Delete and add to ignore list > bin
  • Right click TortoiseGit > Delete and add to ignore list > obj
极度宠爱 2024-08-30 13:13:09

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

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

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

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

Patterns read from the file specified by the configuration variable 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

烟沫凡尘 2024-08-30 13:13:09

@Raphael Pinel 是绝对正确的。如果文件已在 Git 存储库中,则 .gitignore 不起作用。

我使用 VS2019 和 Azure DevOps 作为我的 Git 存储库。这是我修复它的方法。

在 Visual Studio 中,添加 .gitignore 文件(如有必要)并将该文件推送到存储库。

 Team Explorer->Changes->Right Click
 .gitignore->Stage.

然后提交暂存,然后同步。
访问 Azure DevOps 网站。
从 Git 存储库中删除 bin/obj 文件夹。
在 Visual Studio 中,

Team Explorer->Changes->"Undo Changes" to those folders.
Team Explorer->Synch->Pull to update local Git repository.

您现在可以构建项目,Git 将忽略 .gitignore 文件中指定的文件夹。

@Raphael Pinel is absolutely correct. .gitignore doesn't work if the files are already in the Git repository.

I'm using VS2019 and Azure DevOps as my Git repository. Here's how I fixed it.

In Visual Studio, add .gitignore file (if necessary) and push that file to the repository.

 Team Explorer->Changes->Right Click
 .gitignore->Stage.

Then commit staged, then sync.
Go to Azure DevOps website.
Delete bin/obj folders from Git repository.
In Visual Studio,

Team Explorer->Changes->"Undo Changes" to those folders.
Team Explorer->Synch->Pull to update local Git repository.

You can now build your project and Git will ignore the folders as specified in the .gitignore file.

逆光飞翔i 2024-08-30 13:13:09

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

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

仅此而已 2024-08-30 13:13:09

就我而言, bin 和 obj 文件夹嵌套在根 .gitignore 文件的 Project 文件夹下,因此我必须按如下所示添加它:

[PROJECT_FOLDER_NAME]/bin
[PROJECT_FOLDER_NAME]/obj

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

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:

[PROJECT_FOLDER_NAME]/bin
[PROJECT_FOLDER_NAME]/obj

Replace PROJECT_FOLDER_NAME with your project folder name

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文