简体   繁体   English

提交后忽略Git中的文件

[英]Ignoring files in Git after they have been committed

I have recently switched to git. 我最近切换到git。

In my previous and first commit since using git, I noticed it also listed the pyc files during the commit. 自从使用git以来,在上一次提交的内容中,我注意到它还在提交过程中列出了pyc文件。 I didn't think anything about it and commited and pushed them. 我对此一无所获,并承诺并推动了他们。

Now I realize they keep getting updated during the development and its very annoying seeing them in the list. 现在,我意识到它们在开发过程中不断更新,并且很讨厌在列表中看到它们。 It just produces too much noise. 它只会产生太多的噪音。

I did some research and did echo "*.pyc" >> .gitignore in the project directory. 我做了一些研究,并在项目目录中echo "*.pyc" >> .gitignore

This didn't help though as the pyc files are still being shown. 但是,这并没有帮助,因为pyc文件仍在显示。 Could it be that because I have previously committed those pyc files I can no longer ignore them? 可能是因为我以前提交过这些pyc文件,所以我不能再忽略它们了吗? (since they are tracked now and the state has changed again) If so I am damned forever or is there still hope to delete the files in the hindsight from the repository? (因为现在已对它们进行跟踪,并且状态又发生了变化)。如果是这样,我将永远被诅咒,还是仍然有希望从存储库中删除事后看来的文件?

Thanks 谢谢

Just git rm the .pyc files, and make sure your .gitignore is set to ignore them from now on. 只需git rm .pyc文件,并确保从现在开始将.gitignore设置为忽略它们。 You are correct that git will not ignore the committed files because they've already been added. 没错,git不会忽略已提交的文件,因为它们已经被添加了。 If you are keen about not deleting the off the disk, then use git rm --cached to delete the files. 如果您希望不删除磁盘,请使用git rm --cached删除文件。 That just deletes them from the index without deleting from the disk. 那只是从索引中删除它们而没有从磁盘中删除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM