How to ignore certain files in Git

Kohan95 picture Kohan95 · Nov 29, 2010 · Viewed 1M times · Source

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

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

How can I make Git ignore Hello.class?

Answer

Ondrej Slinták picture Ondrej Slinták · Nov 29, 2010

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.