Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: How to ignore certain files in Git

Tags:

git

gitignore

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?

like image 610
Kohan95 Avatar asked Nov 29 '10 22:11

Kohan95


2 Answers

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.

like image 59
Ondrej Slinták Avatar answered Oct 08 '22 13:10

Ondrej Slinták


How to ignore new files

Globally

Add the path(s) to your file(s) which you would like to ignore to your .gitignore file (and commit them). These file entries will also apply to others checking out the repository.

Locally

Add the path(s) to your file(s) which you would like to ignore to your .git/info/exclude file. These file entries will only apply to your local working copy.

How to ignore changed files (temporarily)

In order to ignore changed files to being listed as modified, you can use the following git command:

git update-index --assume-unchanged <file1> <file2> <file3> 

To revert that ignorance use the following command:

git update-index --no-assume-unchanged <file1> <file2> <file3> 
like image 30
Xman Classical Avatar answered Oct 08 '22 15:10

Xman Classical