Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gitignore everything except specific files

Tags:

git

gitignore

I've been reading on Stack Overflow about using gitignore to ignore everything except specific files. I've tried a bunch of different suggestions, but I can't get it to work for me.

Here's what I'm trying to do: I want to exclude everything except one file in my main directory and a couple other files in the subdirectory. So, I want only these files:

flightsofideas.rb
/FlightsOfIdeas/svgExportTools.rb
/FlightsOfIdeas/svgExport.rb

My latest version of gitignore is:

*    
!flightsofideas.rb
!/FlightsOfIdeas/svgExportTools.rb
!/FlightsOfIdeas/svgExport.rb

But git only includes flightsofideas.rb, it doesn't get the files in the subdirectory.

like image 984
Scott Goldthwaite Avatar asked Jul 02 '26 19:07

Scott Goldthwaite


1 Answers

You should add !*/ not to ignore the directories, or it will not look into the directories to include back files.

Still similar problem as What's the difference between Git ignoring directory and directory/*?.

*
!*/
!/flightsofideas.rb
!/FlightsOfIdeas/svgExportTools.rb
!/FlightsOfIdeas/svgExport.rb
like image 133
Landys Avatar answered Jul 04 '26 08:07

Landys



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!