Help with GitIgnore! Need to ignore .jar and classpath

For my team, we have our code on a laptop and my personal pc.
Ive noticed that each time i pull new code and build on whichever computer, i get new .classpath and .jar files made
To me it seems that this is because of small differences in the computers software.
Obviously, i need to ignore these but when i add .jar and .classpath to my gitignore, it doesnt work.

my gitignore file is like this(-- show beginning and end)


.jar
.classpath

This should work, shouldnt it?? Help please!!

It’s likely because your git repository is already tracking those files. When you edit your .gitignore file, the new .gitignore file will not ignore any already tracked files.

Try this: https://stackoverflow.com/questions/6535362/gitignore-after-commit

That only ignores files literally named “.jar” and “.classpath”. If you want to ignore all files with .jar and .classpath extensions, you need to use asterisks:


*.jar
*.classpath

See Git - gitignore Documentation for more information.

I suggest using gitignore.io. Just enter the operating system(s), programming language(s), IDE(s) etc. you use, and then paste the output in your .gitignore file.

Hey, none of what anyone has said has worked somehow, so I’m thinking of just ignoring anything that isnt in the src folder
Sounds bad but could someone write me a quick .gitignore that would do this, only track things in the src folder. I have this but its not working…

Ignore everything in repository root

/*

Files to not ignore

!/.gitignore

Folder to not ignore

!/src/

Thanks!

OP, I think you are going to have to be a bit more specific about what is not working. I strongly suspect the above post contains your answer: adding patterns to the gitignore does not impact files already being tracked.

As far as I know, The most recent example of gitignore you posted likely will not work either, as it would exclude Gradle or eclipse files required to define the project.

Ok so nothing is working so I’ve decided to start a new project. Once I start it and copy the code files, i make it into a repo using eclipse, got that. Make the initial commit, no problem.
After that, what do I add to the .gitignore so that it only tracks things in the src folder, and if that isnt possible , to not track .jar ,.class or .classpath files
I know the answers are simple, but they arent working, so what can I do?

Orr, the problem is when I pull and push from different computers, is that giving me my problem? To me it shouldnt be, because a gitignore should just ignore those types of files! Thanks!

Hmmm, ok.

What files are part of the initial commit? Is it just source code and project files, or does it include the .jar files?

Background facts to keep in mind as you troubleshoot:

“*.<extension>” is the proper syntax for excluding all files with a certain extension.

The tracking of file changes occurs at add/commit time, not on push or pull. As long as files get tracked when the commit is created, all subsequent pushes and pulls will by default include those files.

Ok so what I did was restart my project, manually start the repo from the git shell. Once i had everything tracked, I commited and pushed and then deleted the repo from my computer lol so that i could then clone it from github desktop to no longer have to use the shell from everything( i deleted because for some reason ‘finding’ existing repos from github desktop never worked.
From here , i cloned on the laptop , ran and commited and pushed until i could run on both computers without having any new files.
From here, i did git rm --cached *.jar, commited and pushed, then changed the gitignore accordingly, commited and pushed and voila, no longer getting those pesky .jar files

Thanks everyone for the help, during my troubleshooting i learned more than i ever had about git, and the importance of .class and .classpath files!

Gotcha, glad you got to a working state!

FYI if you’re in the bucket of starting from scratch, here’s the procedure I generally use. I’m not very well versed in github desktop, just git command line.

  1. Create initial set of files - from template, copied in, etc. Get a basic build up and running.
  2. Add a .gitignore . Add file patterns that should be ignored - .jar/.class in your case, maybe others depending on the IDE/Language.
  3. Open a git bash in the root of the folder structure
  4. git init
  5. git remote add origin <URL from github.com>
  6. git add --all
  7. git status
  8. Inspect the output of git status. Confirm no temporary build files, or anything you don’t want archived is staged for commit. Undo staging and edit the .gitignore as needed.
  9. git commit -m “Initial content”
  10. git push origin

This should get one initial commit out on your github server repo with no undesired build files.

FYI - for the procedure you listed above - one downside to it is that your early commit(s) will have the build files in them. This means that git stores data in its backend to recreate them if needed. If you’re not checking out those initial commits, and the total size of the .jar/.classpath files isn’t too large, this isn’t all that bad, and I wouldn’t worry about it. However, if the files happened to be massive, they would slow down clone (and maybe push/pull) operations (even though you’re never actually using them on the latest). Again for FRC purposes this is probably totally not a concern at all, I just come from an industry background where we care about such scalability matters.

1 Like

cookiecutter is a neat tool that can help expedite those templating/setup steps.

1 Like