0

I have a .gitignore file within my project with the following rules:

# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
[Xx]64/
[Xx]86/
[Bb]uild/
bld/
[Bb]in/
[Oo]bj/

I have a specific folder in my application that uses the keyword "Build" but I want to include this particular folder and it's files as part of my commits.

The paths I want to include are as following:

Views/Build/Index.cshtml
Views/Build/Create.cshtml

I've tried the following but it isn't working:

!Views/[Bb]uild/*

What am I doing wrong?

I'm struggling to find an answer to my problem and hope someone can help.

2
  • Btw. you can prefix your ignore rules with / to make the apply at the root, e.g. when build output is only ever built into the root folder.
    – poke
    Commented Jan 6, 2017 at 14:43
  • 1
    Btw. (2), Git will only ignore files that aren’t already tracked by Git, so you can always explicitely add files using git add -f Views/Build/Index.cshtml even if that file is actually ignored (this will effectively turn off the ignore rule for that file, so subsequent changes will also be detected properly).
    – poke
    Commented Jan 6, 2017 at 14:45

1 Answer 1

1

Add !Views/[Bb]uild to your .gitignore file at the bottom (after the other rules). I've tested this with the following file:

# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
[Xx]64/
[Xx]86/
[Bb]uild/
bld/
[Bb]in/
[Oo]bj/

!Views/[Bb]uild

The difference between your attempt and mine was that you added !Views/[Bb]uild/* and I added !Views/[Bb]uild.

I believe the reason that !Views/[Bb]uild/* doesn't work is because it's saying "exclude all contents underneath 'Views/Build' from being ignored", but this by itself has no effect as the directory itself is still ignored. My rule excludes the directory itself (and by extension everything under it).

Edit

This is the tree structure of the directory I've tested this in:

$ tree -a -I .git
.
├── .gitignore
├── hello.cs
├── temp.py
├── temp.txt
├── temp.vi
└── Views
    └── Build
        ├── Create.cshtml
        └── Index.cshtml

This is the output from git status:

$ git status
On branch master

Initial commit

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

        .gitignore
        Views/
        hello.cs
        temp.py
        temp.txt
        temp.vi
4
  • I've tried as you suggested and still no joy. After running git check-ignore, the global rule still seems to be applied: $ git check-ignore -v XXX/Views/Build/Status.cshtml .gitignore:20:[Bb]uild/ XXX/Views/Build/Status.cshtml
    – jgill09
    Commented Jan 6, 2017 at 14:44
  • 1
    @jgill09 I get that output from git check-ignore too, but if you try unstaging and restaging all changes you should see it work (git reset && git add -A && git status)
    – Tagc
    Commented Jan 6, 2017 at 14:51
  • Perfect, that's worked. Thank you.
    – jgill09
    Commented Jan 6, 2017 at 15:01
  • @jgill09 Great. If it solves your problem, I'd appreciate if you'd accept the answer. :)
    – Tagc
    Commented Jan 6, 2017 at 15:21

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