Avatar Ran Qiangjun

Git: .gitignore -- exclude everything except a specific directory

Submitted by jungle on Sun, 09/22/2019 - 02:33

Example to exclude everything except a specific directory foo/bar (note the /* - without the slash, the wildcard would also exclude everything within foo/bar):

  1. $ cat .gitignore
  2. # exclude everything except directory foo/bar
  3. /*
  4. !/foo
  5. /foo/*
  6. !/foo/bar

Another example from ansible

  1. # Ignore all folders under roles but the basic folder
  2. /roles/*
  3. !/roles/basic
©2019 ranqiangjun.com. All rights reserved.