-2

I want git to track changes to a specific folder named BananaProject.Widget.Controls. The folder lies at the root directory of the project, just as .gitignore.

I am trying to ignore anything else except the activity on that folder but GIT does not track a new file created inside that directory. On the contrary, it tracks changes to files that already exist.

Here is the .gitignore

*
!/BananaProject.Widget.Controls/*

What am I doing wrong?

Edit

Because I want to create C# files I also tried this without any success

*
!/BananaProject.Widget.Controls/*.cs
Themelis
  • 4,048
  • 2
  • 21
  • 45
  • 1
    * is a wildcard so i am thinking, if you have it the way it is in your code snippet, then you may be telling git to ignore all files in the directory. – Afia Nov 22 '19 at 21:31
  • That's true @AfiaUdofia but the `!` negates the pattern. So the first line means ignore everything and the second line means except that pattern. – Themelis Nov 22 '19 at 21:33
  • shouldn't they be on the same line? – Afia Nov 22 '19 at 21:34
  • I believe every pattern should be in its own line. – Themelis Nov 22 '19 at 21:35
  • 1
    Does this answer the question? https://stackoverflow.com/questions/5241644/using-gitignore-to-ignore-everything-but-specific-directories or this? https://stackoverflow.com/questions/1248570/how-do-i-tell-git-to-ignore-everything-except-a-subdirectory –  Nov 22 '19 at 21:37
  • Unfortunately no @Amy, shouldn't this be a simple task? – Themelis Nov 22 '19 at 21:46
  • It is a simple task, yes. –  Nov 22 '19 at 21:48
  • Try removing the leading `/`. That's rooting the path to your drive root, not the project root. –  Nov 22 '19 at 21:53
  • Doesn't work either. @Amy – Themelis Nov 22 '19 at 21:58
  • Git doesn't track new files; you have to `git add` them. – Kaz Nov 22 '19 at 22:30
  • If you're on a system that's case-insensitive, does your directory name match the case exactly? – bk2204 Nov 23 '19 at 03:16
  • Possible duplicate of [How do I tell Git to ignore everything except a subdirectory?](https://stackoverflow.com/questions/1248570/how-do-i-tell-git-to-ignore-everything-except-a-subdirectory) – phd Nov 23 '19 at 10:47
  • what does `git status --ignored` say? – eftshift0 Nov 25 '19 at 14:04
  • Just in case, even if the files are being ignored (and you can't figure out why), you can still force git to track them by using -f on `git add`. – eftshift0 Nov 25 '19 at 14:06

1 Answers1

0

The following works for me, with Git version 2.17.1

Directory tree:

/tmp
*--- git/
    *--- .gitignore
    *--- foo/
        *--- bar

Contents of .gitignore:

./*
!foo/

Output of git status:

Untracked files:
  (use "git add <file>..." to include in what will be committed)

    .gitignore
    foo/

I can then add foo/ and it tracks the file bar.

Pesho_T
  • 814
  • 1
  • 6
  • 18