简体   繁体   中英

Git, ignore all files except a few in subdirectories

I've been reading around forever now without a solution that matches my setup.

I am developing a extra for a cms and I don't want to keep all the cms files in my repo.

The files I want to keep are:

/_build/ [everything inside here]
/core/components/mycomponent/ [everything inside here]

However, I'd like to ignore all the other files in the core directory as well as other directories.

How do I express this in a gitignore? I've tried with the new syntax from 1.8.2, but I just can't get it to work.

Just this simple approach ignores the subdirectories within _build

*

!.gitignore

!/_build
!/_build/**

If you have a *, you'll drop all files/directories.

If you have /*, you'll drop all directories and files at top level.

It looks like what you really wanted was:

/*
!.gitignore
!/_build
!/core

In the root directory of your project:

*
!.gitignore
!_build/
!core/

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