仅允许子目录中的一些文件使用.gitignore

Dmi*_*sev 25 gitignore

我有这样的dir结构:

static
    admin
    ajax_upload
    books
    css
    font
    media
    robots.txt
templates
src
build
lib
Run Code Online (Sandbox Code Playgroud)

我想忽略以下的骗局:

  • LIB
  • 建立
  • SRC
  • 静态的

我想允许以下内容:

  • 静态/ CSS /自举styled.css
  • 静态/ CSS/main.css的
  • 静态/ CSS /字体 - *CSS
  • 静态/字体
  • 静态/媒体/为Default.png
  • 静态/的robots.txt
  • 模板

所以我使用以下.gitignore:

# Ignore
/lib
/src
/build
/static/*

# Allow
!/static/css/bootstrap-styled.css
!/static/css/main.css
!/static/css/font-*.css
!/static/font
!/static/media/default.png
!/static/robots.txt
Run Code Online (Sandbox Code Playgroud)

但它不能正常工作.你能帮助我吗 - 我在这里做错了什么?TIA!

细节

真正的项目结构是这样的:

static
    admin
        css
        img
        js
            admin
    ajax_upload
    books
    css
    font
    media
        uploads
            blog
            gallery
        default.png
    robots.txt
templates
src
build
lib
Run Code Online (Sandbox Code Playgroud)

Dmi*_*sev 34

那么,.gitignore对我有用如下:

# Ignore
lib/
src/
build/
static/**/*

# Allow
!static/css/bootstrap-styled.css
!static/css/main.css
!static/css/font-*.css
!static/font/*
!static/media/default.png
!static/robots.txt
Run Code Online (Sandbox Code Playgroud)


Din*_*ing 6

请尝试以下操作:

# Ignore
/lib/
/src/
/build/
/static/

# Allow
!/static/css/bootstrap-styled.css
!/static/css/main.css
!/static/css/font-*.css
!/static/font
!/static/media/default.png
!/static/robots.txt
Run Code Online (Sandbox Code Playgroud)

我认为应该可以。