1 23
1 23

Reputation: 1

Ignore folders in git but not the files in them

I have created a Java project with IntelliJ. The project structure looks like:

rootfolder\projectname\src\*.java

And I would like to upload my Java classes to GitHub, but without src folder, like this:

rootfolder\projectname\*.java

Upvotes: 0

Views: 127

Answers (2)

Xiaojiba
Xiaojiba

Reputation: 146

In your .gitignore (at the root of your project)

You can add :

project/a/*/

Note that the last slash means it's a directory and is therefore important to keep

Upvotes: 0

jthill
jthill

Reputation: 60527

project/a/src/*
!project/a/src/files

Ignoring a directory is a summary execution, git's auto-add never even scans an ignored directory's contents (which is kind of the point of ignoring a directory, build systems can spew an astonishing amount of junk), so to ignore everything in a directory except a few things, you ignore everything in that directory except those few things, you don't ignore the entire directory.

Upvotes: 1

Related Questions