3

I ignore all files except for some folders as shown below in the .gitignore file.

  *
  !.gitignore
  !/sample1/test1/
  !sample1/test1/*

My issue is , it only keeps track of files under test1 folder which already exist , when i make new file, it ignores to track it.

may i know any solution ?

2 Answers 2

2

You can not directly include already excluded nested direcory. * excludes everything so firstly you need to negate exclusion for sample1 directory and later for test1 subfolder. That will work as you expect:

*
!.gitignore
!/sample1/
/sample1/*
!/sample1/test1
!/sample1/test1/*
8
  • Thanks , but it still dont track new files under test1
    – Pentagon
    Commented Jul 6, 2018 at 12:54
  • 1
    @Pentagon Just add !sample1/test1/* last and it will.
    – klutt
    Commented Jul 6, 2018 at 13:05
  • @klutt : i still cant track new files under test1
    – Pentagon
    Commented Jul 6, 2018 at 13:09
  • You're right @klutt. Edited comment above. I tested it and works as expected for me.
    – mrf
    Commented Jul 6, 2018 at 13:14
  • @mrf , thanks for your edit, and it work under test1, and may i know if make other sub directory , should add all like above, or there is some way to accept all inherit folders. let say /sample1/test1/test2/test3/...
    – Pentagon
    Commented Jul 6, 2018 at 13:38
1

This works when I try it:

*
!.gitignore           
!sample1/
sample1/*
!sample1/test1/
!sample1/test1/*
1
  • Thanks Klutt, but is there any way to get whole nested folders at once? let say we have many nested folders like /sample1/test1/test2/test3/... in this case how we exclude whole subfolders under sample1 folder
    – Pentagon
    Commented Jul 6, 2018 at 13:42

Not the answer you're looking for? Browse other questions tagged or ask your own question.