Git:如何忽略 Git 中的某些文件 [英] Git: How to ignore certain files in 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
?
How can I make Git ignore 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:如何忽略 Git 中的某些文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!