Git仍会添加并跟踪.gitignore中标记的文件夹 [英] Git still adds and tracks folders marked in .gitignore

查看:146
本文介绍了Git仍会添加并跟踪.gitignore中标记的文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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"中可以解决问题,但由于某种原因,它根本无法正常工作.在几天之内,我一直无法向仓库提交任何东西,因为每次我尝试执行push命令时,它都会尝试发送100k文件,然后冻结并超时.

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.

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

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

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?

推荐答案

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

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.

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

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

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

git rm -r --cached .

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

This removes everything from the index, then just run:

git add .

提交:

git commit -m ".gitignore is now working"

这篇关于Git仍会添加并跟踪.gitignore中标记的文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆