简体   繁体   中英

git ignore all folder except a few with a common prefix

I want to ignore all files and folders except five folders that begin with a certain prefix. For example

  1. Folder one
  2. Folder two
  3. prefix_folder_one
  4. prefix_folder_two

I want to ignore everything except folders 3 and 4 and their content

I tried this but it didn't work

*
!.gitignore
!/prefix_*

I also tried writing the full names of folder 3 and 4 but it didn't work either. git status tells me that there are no files to commit.

This will ignore all root files and root sub-directories, excluding the .gitignore file and the directories with the prefix prefix_

/*
/*/
!.gitignore
!/prefix_*

Git should now track the files in the directories with prefix_ and ignore the 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