Git 仍然添加和跟踪 .gitignore 中标记的文件夹

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

Git still adds and tracks folders marked in .gitignore

gitgitignore

提问by Patrick Simard

I have a few folders in Git added in my ".gitignore" file. They contain over 100k files. Mainly images, tmp and cache stuff. What I need is to be able to commit changes to my code with out committing what happens in those folders.

我在“.gitignore”文件中添加了一些 Git 文件夹。它们包含超过 10 万个文件。主要是图像、tmp 和缓存的东西。我需要的是能够提交对我的代码的更改,而无需提交在这些文件夹中发生的事情。

I thought adding them into the ".gitignore" would do the trick but for some reason it's not working at all. I haven't been able to commit anything to the repo in days because every time I try the push command it tries sending 100k files then it freezes and times out.

我认为将它们添加到“.gitignore”可以解决问题,但由于某种原因它根本不起作用。几天来我一直无法向 repo 提交任何内容,因为每次我尝试 push 命令时,它都会尝试发送 100k 文件,然后它会冻结并超时。

root@serveur [/home/***/***]# git push origin master
Password:
Counting objects: 110300, done.

How can I force Git to reindex the tree while taking in consideration the ignored folders so I can finally commit all the changes I made to the code?

如何在考虑被忽略的文件夹的同时强制 Git 重新索引树,以便我最终可以提交对代码所做的所有更改?

回答by dax

The reason it isn't working is (probably) because you added some of those files before you added the .gitignore- so you have to remove them from git before they're able to be ignored.

它不起作用的原因(可能)是因为您在添加之前添加了其中一些文件.gitignore- 因此您必须在它们被忽略之前从 git 中删除它们。

Source: https://stackoverflow.com/a/1139797/2128691

来源:https: //stackoverflow.com/a/1139797/2128691

First, commit any outstanding code changes, and then, run this command:

首先,提交所有未完成的代码更改,然后运行以下命令:

git rm -r --cached .

This removes everything from the index, then just run:

这将从index 中删除所有内容,然后运行:

git add .

Commit it:

提交它:

git commit -m ".gitignore is now working"