Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git ignore a specific file in Eclipse

Tags:

git

eclipse

egit

I guess this kind of question has been asked many times (and I've seen several questions on SO dealing with this subject) but I still have a problem to ignore a file in my Git.

The structure of my project looks like this:

myProject/
    .gitignore
    src/test/java/packageName/
        Main.java

I would like to ignore Main.java (the file is different between each user).


.gitignore file

.settings
.project
.classpath
target/
test-output/
node_modules/**
.orig

I've tried:

  • Adding src/test/java/packageName/Main.java to my .gitignore.

  • Creating a .gitignore file in src/test/java/packageName/ that just contains Main.java.

Both solutions have no effect: I still see Main.java in the Git Staging view after restarting Eclipse.


I guess the solution is simple, but I'm stuck on it for several hours, and I hope you can help me.

Thanks! :-)

UPDATE

All Git users have Main.java, but the class is different from one person to another (user name hardcoded in the class).

I want this class to be present on the HEAD branch (so that new developers can recover it), but each developer can have a local version (invisible in Git Staging).

like image 643
Mistalis Avatar asked Jul 11 '16 09:07

Mistalis


2 Answers

Your problem is probably that Main.java is already in your index. The solution

First make it disappear

git rm src/test/java/packageName/Main.java

then add it to your gitignore

echo "src/test/java/packageName/Main.java" >> .gitignore

now commit these changes

git add .gitignore
git commit -m "please ignore me!"

And it should work :-)

You can now recreate your Main.java and it should no longer appear in git status.

like image 175
BartBog Avatar answered Oct 18 '22 15:10

BartBog


Able to achieve it in Eclipse Oxygen. Here step follows.

  1. Enable "Automatic Ignore" .ignore file from window-> preference. enter image description here

  2. Right Click on file/folder to ignore. For example right click on target folder(contains .class file). Team -> Ignore

  3. Go to Staging view, you will see .ignore file generate.
  4. Right click on .ignore file and ignore that again.
like image 38
Swarit Agarwal Avatar answered Oct 18 '22 16:10

Swarit Agarwal