简体   繁体   中英

git exclude everything in folder except a subdirectory

I am working on a node js project and I am creating a node module that for now want have it added to the project I am working on. So in my gitignore I put the following but it did not work

node_modules/*
!node_modules/zephyr-rest

The zephyr-rest is a directory, so I want just that directory and its files to be saved. I do not want any other sub directory under node_modules to be versioned. Thanks

Try this, worked for me.

node_modules/*
!node_modules/zephyr-rest/

After git status it will show like this

Untracked files:
  (use "git add <file>..." to include in what will be committed)

  node_modules/

Don't worry because git status just tells the top-most untracked folder as untracked not every subfolder, so this tells there is an untracked folder node_modules . Doing git add node_modules should add just node_modules/zephyr-rest/

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