在已经跟踪大量文件的现有存储库上应用gitignore [英] Apply gitignore on an existing repository already tracking large number of files

查看:107
本文介绍了在已经跟踪大量文件的现有存储库上应用gitignore的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的存储库中有一个现有的Visual Studio项目。我最近在我的项目下添加了一个.gitignore文件,我假设它告诉Git忽略文件中列出的文件。



我的问题是,所有这些文件都已被跟踪,据我所知,Git不会忽略在将规则添加到此文件之前已经跟踪的文件忽略它。



建议使用: git rm --cached 并手动取消跟踪它们,但这将永远让我永远经历他们一个接一个。



我曾想过删除存储库并重新创建它,但这次使用.gitignore文件存在,但必须有更好的方法来执行此操作。

解决方案

答案 a>解决了我的问题:

提交所有挂起的更改,然后运行以下命令:

  git rm -r --cached。 

这将删除索引中的所有内容,然后运行:

  git add。 

提交:

  git commit -m.gitignore现在正在运行


I have an existing Visual Studio project in my repository. I recently added a .gitignore file under my project and I assume that tells Git to ignore the files listed in the file.

My problem is that all those files are already being tracked and as far as I know Git will not ignore a file that was already tracked before a rule was added to this file to ignore it.

It was suggested to use: git rm --cached and manually un-track them but that's going to take me forever to go through them one by one.

I thought about deleting the repository and recreating it again but this time with .gitignore file present, but there must be a better way to do this.

解决方案

This answer solved my problem:

Commit all pending changes, then run this command:

git rm -r --cached .

This removes everything from the index, then just run:

git add .

Commit it:

git commit -m ".gitignore is now working"

这篇关于在已经跟踪大量文件的现有存储库上应用gitignore的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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