如何忽略Git中的某些文件 [英] How to ignore certain files in Git

查看:87
本文介绍了如何忽略Git中的某些文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有文件Hello.java的存储库.当我编译它时,会生成一个附加的Hello.class文件.

I have a repository with a file, Hello.java. When I compile it, an additional Hello.class file is generated.

我在.gitignore文件中为Hello.class创建了一个条目.但是,该文件似乎仍被跟踪.

I created an entry for Hello.class in a .gitignore file. However, the file still appears to be tracked.

如何使Git忽略Hello.class?

推荐答案

问题是.gitignore只会忽略以前未跟踪过的文件(git add).运行git reset name_of_file取消暂存文件并保留它.如果您还想从存储库中删除给定的文件(在推送之后),请使用git rm --cached name_of_file.

The problem is that .gitignore ignores just files that weren't tracked before (by git add). Run git reset name_of_file to unstage the file and keep it. In case you want to also remove the given file from the repository (after pushing), use git rm --cached name_of_file.

这篇关于如何忽略Git中的某些文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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