简体   繁体   中英

gitignore everything except specific files

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM