Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How not to display the .class in git

I don't want to display .class files when executing git status.

I created a file named .gitignore and entered the .class in the file but nothing happened.

What is the best way to prevent the .class file from being displayed when you execute git status command?

like image 463
Rodel Sarate Avatar asked Jan 10 '13 05:01

Rodel Sarate


People also ask

How do I ignore a .class file in git?

The easiest and most common way to ignore files is to use a gitignore file. Simply create a file named . gitignore in the repository's root directory. Then, add names and patterns for any files and directories that should not be added to the repository.

How do I remove a class from a git repository?

You should do a git rm target/classes/test/java/NewTest$1. class . You can also do git add -A which will stage deletes as well. You may need to do git add -A :/ if on a newer version of git.


2 Answers

Make sure your .class files were not already added to the index.
You would need to git rm -r --cached path/to/.classfiles/ those files first.
(they will still be on the disk, but no longer part of the git index, and will be ignored by the git status)

If you don't want any .class file versioned (but you didn't include them in the .gitignore initially), as Michal Stefanow comments below:

git rm -r --cached *.class 

Mark adds in the comments:

For Windows TortoiseGit users like me, follow the instructions in this related post to do the git in the GUI

Right click that file, choose TortoiseGit -> Delete (keep local).
This does git rm --cached.

like image 115
VonC Avatar answered Sep 17 '22 18:09

VonC


You probably actually want to add *.class into your .gitignore file, not .class - the former will match any class file (because of the wildcard *), whereas the latter only matches a file named exactly .class.

like image 28
Amber Avatar answered Sep 18 '22 18:09

Amber