简体   繁体   中英

Recursively ignore folder in git

How to ignore all folders with name build , bin . I tried doing this

**/bin/
**/build/

but it doesn't work. in git status i see

#   new file:   BS/server/build/obj/sender.o
#   new file:   BS/server/build/obj/sendistate.o
#   new file:   BS/server/build/obj/serializedata.o
#   new file:   BS/client/bin/gc.sample.xml
#   new file:   BS/client/bin/mkab.qss
#   new file:   BS/client/bin/mkaberr.qss
#   new file:   BS/client/build/debug/application.qss
#   new file:   BS/client/build/debug/config.xml

If you want to ignore directory, you should be "directoryname/". For example

bin/
build/
  • Test example with empty .gitignore :

➜  /tmp  mkdir -p test/ab/{bin,build}  
➜  /tmp  touch test/ab/{bin,build}/file.txt
➜  /tmp  tree -a
➜  /tmp  tree -a test 
test
└── ab
    ├── bin
    │   └── file.txt
    └── build
        └── file.txt

3 directories, 2 files
➜  /tmp  cd test
➜  test  git init
Initialized empty Git repository in /tmp/test/.git/
➜  test git:(master) ✗ git add -An
add 'ab/bin/file.txt'
add 'ab/build/file.txt'
  • Test example with filled .gitignore :

➜  ~  cd /tmp 
➜  /tmp  mkdir -p test/ab/{bin/,build}
➜  /tmp  touch test/ab/{bin,build}/file.txt
➜  /tmp  cat > test/.gitignore
bin
build
➜  /tmp  tree -a test 
test
├── ab
│   ├── bin
│   │   └── file.txt
│   └── build
│       └── file.txt
└── .gitignore

3 directories, 3 files
➜  /tmp  cd test 
➜  test  git init
Initialized empty Git repository in /tmp/test/.git/
➜  test git:(master) ✗ git add -An
add '.gitignore'

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