0

I am trying to use the .gitignore to help me filter out folders. I need an inner-folder but not anything else in the folder which contains this inner-folder.

I tried this:

.gitignore

**/outer-folder
!inner-folder/

This does not seem to work. The entire outer-folder is gone. Why?

Also, I would appreciate if someone help me with a relevant question: Maybe the reason this does not work is because the .gitignore never get re-executed after I added these two lines of code. So how to force Git run .gitignore?

I tried touch .gitignore but some bash (e.g. vscode) does not know command touch. Any better solution?

tic30
  • 49
  • 2
  • 14
  • Also, `.gitignore` never gets "executed". Git will always use the current version of the file. It may *seem* not to work if you are trying to ignore a file that is already tracked by git, in which case you have to `git rm --cached`. – 0x5453 Jun 01 '17 at 15:12
  • `foo/` ignores `foo/` itself and everything underneath it. `foo/*` ignores everything underneath `foo/`. If `foo/` has been ignored, then nothing underneath it can be re-included. So what you need is `**/outer-folder/*`. – ElpieKay Jun 01 '17 at 15:16
  • @0x5453 - Not a good duplicate. If you read the question, you'll see that OP already *tried* using `!` (the answer to the linked question); and indeed directory exclusions are something of a special case here, wherein that doesn't work. – Mark Adelsberger Jun 01 '17 at 15:18
  • @ElpieKay - Have you tested that solution? Because in my tests (both previously when this has been discussed, and just now) it still doesn't work. – Mark Adelsberger Jun 01 '17 at 15:19
  • 1
    Thank you all. As @0x5453 mentioned, the solution is posted in the other question. I need to add `/*` after `outer-folder` – tic30 Jun 01 '17 at 15:26

0 Answers0