简体   繁体   中英

How to make git ignore a sub directory group with gitignore pattern?

I've a directory projects/ in root directory. the root directory is added to git. in projects I've several subdirectories. But I want to track only projects/admin not projects/x nor projects/y . What ignore rule I need to write in .gitignore ?

You can use a negative ignore clauses, eg:

project/*
!project/admin
!project/admin/*
projects/*
!projects/admin

The ! prefix before a line negates it; ie the directory or file given in that line will not be ignored.

You can put a .gitignore file directly in the projects directory and it will only affect that directory.

So, in projects/.gitignore , just put:

admin
x
etc

You can add a .gitignore to each folder you don't want to track by running touch project/x/.gitignore . Git will then ignore the contents of each of those folders.

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