'Git ignore a specific file in Eclipse
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.javato my.gitignore.Creating a
.gitignorefile insrc/test/java/packageName/that just containsMain.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).
Solution 1:[1]
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.
Solution 2:[2]
Able to achieve it in Eclipse Oxygen. Here step follows.
Solution 3:[3]
For disappearing auto-generated compiled .class like files from Git Staging view, Please follow following steps in eclipse.
- Refresh Repository
- Open navigator perspective (You can search this in perspective).
- Now look for .gitignore file in the project directory if not present you can create this file in the project directory.
- add the following entries to the .gitignore file -
/.class
/bin/
OR
.class
bin/
- Now save the .gitignore file and refresh the repository or eclipse.
The unwanted files are will be disappeared.
Solution 4:[4]
In eclipse where all the projects names are placed right next to there's small face down arrow ?? click on it then uncheck Class resources Then you are good to go ???
Solution 5:[5]
Make a copy of
Main.javaon your desktop.Delete
Main.javafiles from your project.Add Main.java to your
.gitignore.Commit these changes.
Place the
Main.javafile from your desktop back to your project.
Voila! ?
It won't be part of your git index anymore ?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Swarit Agarwal |
| Solution 3 | Tainoor |
| Solution 4 | Jeyhun |
| Solution 5 | Alice Andrée Thiel |

