Ignore everything expect all subfolders / files in .gitignore - eclipse

I want to allow all files (and their parent folder) within a specific directory of my eclipse project.
I want to allow all files within the libs folder
Example
RootFolder
EclipseProjects
ProjectOne
build
src
WebContent
libs
lib1
file.jar
file1.jar
lib2
file3.jar
file4.jar
etc.jar
In the root of git I have my .gitignore, which includes many variations on the same folder/files
I'm trying to just allow the jars to see if that will work too.
#Relevant lines of .gitignore
#Ignore
*.jar
#Allow
!libs/
!libs/*
!libs/*/*
!libs/**.jar
!/libs/
!/libs/*
!/libs/*/*
!/libs/**.jar
!libs/lib/*.jar
I cannot get this to work, any suggestions?

This worked for me
!**/libs/**/*

Related

.gitignore not ignoring a folder within a directory

It seems a straightforward one, but having researched multiple ways to do it, I can't gitignore a folder within a directory.
I have a root directory which contains all of my code in it. Because it has some back-end NodeJS stuff in it, it has a 'node_modules' folder which contains hundreds of files. As a result, when I try to upload the entire parent folder, GitHub says there's too many files to upload and tells me to reduce the number I'm uploading.
The crucial part is though, the folder has to be uploaded as a whole, as it itself is within a GitHub repository with other files with different folders in.
That means when I go onto my repository, I need this folder's files to display within the folder, and not separately within the repository. I need all of the files to be within this folder, within the parent repository, excluding the node_modules folder.
For example ->
Parent repository -> Child Directory (what I'm uploading) -> Individual files
I've tried to add the node_modules folder to my gitignore through the following methods:
Adding: node_modules/ to my gitignore file
Writing: echo node_modules >> .gitignore through my terminal
Adding a separate gitignore file within my node_modules file with a * in it
None of them have worked and I can't find any other solutions. For reference I'm using a Mac.
Does anyone have any idea what I'm doing wrong, or how it'd be best to do it?
By default, you do not need to include the node_modules folder in your repositories because the package.json file contains all of your project's dependency information. This means that anyone who clones your repository can run npm install and have the entire node_modules folder without problems.
To solve this you can create your own .gitignore file, creating a new file at the root of your project and renaming it to .gitignore (writing exactly that way). Then you can open it with any text editor and add */node_modules to one of the lines.
This will likely solve your problem.

Github ignore multiple node_modules

Im having two kind of node_modules in my folders.
One in the root folder, that works fine, but one also in the folder called "html/app" ( so would be html/app/node_modules )
Why wont it ignore it? it adds everything in the node_modules app folder when i do the command "git commit ".
Current .gitignore contains:
/dist
/tmp
/out-tsc
# dependencies
/node_modules
/html/app/node_modules
html/app/node_modules
If I understood your question right - you want to ignore both node_modules folders.
Try to cut that folder from project, then commit it and then return node_modules folder back.
Future commit's would ignore both folders.
EDIT: Probably it works in that way now because of that git already track that folder.

Merge the src folder in Eclipse

How can I merge the src folder in eclipse without showing the packages,into a single folder.
i
I decided that, as #C-Otto said if you don't need resources or tests then they can remove as source folders. And these are not packages.
To remove as source folders.
Goto:
Project->Properties->Build Path->Sources Tab and remove what you wish :)

Do i run git init in the src folder or in the project folder of my workspace?

I couldn't find a question that similar to mine but the point I'm asking is where do I run git init? Do I run it in the src folder where my code is or in the project folder which contain the src folder and a bin folder? I'm working with eclipse and gitBash. Hope this is enough info.
What do you mean by builded project? Are you referring to .classpath, .project, .settings
When you create a repo, you need to include anything needed to actually build the project.
That include the src/ folder, but also other configuration files.
Those can include the .project (if it has only relative paths, easily reused by others), and the .classpath: see ".classpath and .project - check into version control or not?".
The settings/ folder can also be included 5see "Which eclipse files belong under Version Control", but not the .metadata/ subfolder.
It even can include settings for other IDEs like IntelliJ IDEA, if other contributors are using that tool.
It would not include the bin/ folder, typically added in a .gitignore, because its content is regenerated on demand (built).
Run it in the Project folder.
src folder contains the code files mostly. But supporting resources may be included in the other folders. And you will need to add everything to git without which project may have problem running.

gitignore for folder of eclipse projects

I am working following a set of java swing tutorials, each is an Eclipse project, keep them in a workspace. I init a git repository in the workspace folder (mac), and upload to github. When I download this folder in another computer (linux), the projects are not recognized as such, and opening/importing in Eclipse fails. Says: 'Folder not recognized as project'. What is the best way to handle a collection of projects in git?
If you want to have all of your Eclipse project data across your machines, you will have to add the following files/folders to Git:
.classpath
.project
.settings (folder)
Make sure that these are not ignored in either your local or globale .gitignore files.
Ignore things like the bin and target folders, since they contain the compiled classes and shouldn't be added to Git.
Regarding the failed import: as #nwinkler writes, Eclipse looks for the .project and .classpath files so you need to add them (and the .settings directory) to your git repository.
Regarding .gitignore, I typically put the workspace stuff there (and then do import existing projects in eclipse after cloning):
That is,
.metadata/.plugins
.metadata/.lock
.metadata/.log
and then for each project, the bin folder
project_dir/bin
and any other generated files