Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignore .classpath and .project from Git

I keep myself telling me and others not to commit .classpath and .project files and use Maven.

Somehow, Junior developers always ignore certain rules and commits those files and it's much better to have such files for newbies who can jump and start using the code.

Now from myside, I would like to try/do something. When I clone the repo, I will get .classpath and .project files and certainly they get modified in my system.

But I want them not to be committed and should always be ignored while synchronizing with Git. So that my changes in local system doesn't mess up with Git and Git changes of those files doesn't mess up my local files.

How do I achieve this? Anyway to mark those files to be ignored in such a way?

like image 267
RaceBase Avatar asked Sep 23 '13 08:09

RaceBase


People also ask

How do I ignore a .project file in Git?

If you want to ignore a file that you've committed in the past, you'll need to delete the file from your repository and then add a . gitignore rule for it. Using the --cached option with git rm means that the file will be deleted from your repository, but will remain in your working directory as an ignored file.

Do we need to commit .classpath file?

classpath file is make sure you don't reference files outside of your project. Eclipse stores the location of these files with a full filepath, and you would need to make sure other developers had those files in exactly the same place. Show activity on this post.

What is .classpath and .project files?

Basically, . project files store project-settings, such as builder and project nature settings, while . classpath files define the classpath to use during running.


Video Answer


1 Answers

If the .project and .classpath are already committed, then they need to be removed from the index (but not the disk)

git rm --cached .project git rm --cached .classpath 

Then the .gitignore would work (and that file can be added and shared through clones).
For instance, this gitignore.io/api/eclipse file will then work, which does include:

# Eclipse Core       .project  # JDT-specific (Eclipse Java Development Tools)      .classpath 

Note that you could use a "Template Directory" when cloning (make sure your users have an environment variable $GIT_TEMPLATE_DIR set to a shared folder accessible by all).
That template folder can contain an info/exclude file, with ignore rules that you want enforced for all repos, including the new ones (git init) that any user would use.


As commented by Abdollah

When you change the index, you need to commit the change and push it.
Then the file is removed from the repository. So the newbies cannot checkout the files .classpath and .project from the repo.

like image 144
VonC Avatar answered Sep 18 '22 08:09

VonC