1

This is how my .gitignore looks like:

# User-specific files
*.userprefs
!*.ini
!*.gitkeep
!*.bat

# Build results

[Bb]in/
[Dd]ebug/

What I want to achieve is to ignore all files in project/bin/debug but keep the files like *.ini *.bat and etc.

.gitignore is location in root folder:

rootfolder\project name\bin\Debug
philxtian
  • 99
  • 8

3 Answers3

1

Use ! operator to negate pattern:

*.bat
!myfile.bat

In your case it's better to use .gitignore in specific directory. You should make .gitignore file in project/bin/debug with a content:

*.*
!*.bat

Or you can do it in your project main .gitignore:

MyFolder/*
!MyFolder/NotIgnored.txt

Without * it won't work.

Keep in mind that already staged files won't be ignored. You need to unstage them using git rm --cached <file>

M. Twarog
  • 2,418
  • 3
  • 21
  • 39
1

This works well for me. Add wildcard to your folders, and define the exceptions at the bottom.

# Build results    
[Bb]in/*
[Dd]ebug/*

# User-specific files
*.userprefs
!*.ini
!*.gitkeep
!*.bat
crea1
  • 11,077
  • 3
  • 36
  • 46
0

I solved this by modifying the .gitignore of my root folder to:

# User-specific files
*.userprefs
!*.ini

# Build results
![Bb]in/
[Bb]in/*
![Dd]ebug/

Then creating another .gitignore file inside rootfolder/project/bin/debug/ directory with the ff:

*
!*.ini
!*.bat

Hope this can help someone in the future.

And btw, I got my .gitignore file from: https://www.gitignore.io/api/visualstudio

philxtian
  • 99
  • 8