0

When I pushed my project to github I needed a problem.The structure of my project like this: enter image description here

Now I want to upload .gitignore README.md and all of directory d2.

I don't want to write directory in .gitignore because the project not only has d1 I don't want to upload.There so many directory(d3,d4,d5) I don't want to upload.

I want to find a way that I can ignore all the directory except d2.

I have tried to write .gitignore like this:

* !/d2/ !.gitignore !./README.md

But it didn't work.

Do anyone know how to do?Thanks.

Sineatos
  • 827
  • 1
  • 7
  • 13
  • Possible duplicate of [this](http://stackoverflow.com/questions/5241644/using-gitignore-to-ignore-everything-but-specific-directories) ? – Spotted Jul 14 '16 at 09:21

1 Answers1

0

You may use the following .gitignore.

/*
!/d2/
!.gitignore
!README.md

* ignores all files in directories in all depth, while /* only ignores the files and directories under the root level.

By the way, if you want that it still works with *, you need to add !/d2/** as follows.

*
!/d2/
!/d2/**
!.gitignore
!README.md
Landys
  • 7,169
  • 3
  • 25
  • 34