0

I've researched this and I can't seem to bump on a working solution. I have a repo locally and want to ignore everything in it except two files, since those are the only ones necessary to build the program.

What I've tried is this:

Contents of .gitignore:

# Ignore everything
*

# not these files...
!.gitignore
!ApiTest/KLM_Service.cs
!ApiTest/Program.cs

The structure of my repo is this:

.git
ApiTest
  bin
  obj
  Properties
  App.config
  KLM_Service.cs
  Program.cs
.gitignore

I'm on Windows using GIT Bash.

Any ideas on how to solve this?

user3046061
  • 353
  • 4
  • 14
  • "It is not possible to re-include a file if a parent directory of that file is excluded." - http://git-scm.com/docs/gitignore – ctor Aug 21 '14 at 15:53
  • I can't test this since I'm on mobile now, but would reversing the everything rule with the file ignores work? – user3046061 Aug 21 '14 at 15:59
  • 1
    Nope, as the link says, there is no way to re-include a file where a parent directory of said file has been exluded. – ctor Aug 21 '14 at 16:02
  • I know this is a little old, but check out [this Stack Overflow answer](http://stackoverflow.com/a/16318111/1386201) for a little more information about un ignoring a nested file. Again, not a best practice, but it is possible if you un-ignore all the way down the path, one folder at a time. – Don Oct 14 '15 at 19:15

1 Answers1

2

Based on your repo layout, I would strongly recommend against ignoring everything. While there are a lot of autogenerated files that you don't care about, the autogenerated filenames will never change. Your source code filenames will definitely change, though, which would force you to keep your .gitignore constantly up-to-date.

Since this is C# code, why don't you use a C#-specific .gitignore to start off, like this one?

nneonneo
  • 171,345
  • 36
  • 312
  • 383
  • I'm probably never gonna mess with this again, so that's the motivation. I'd like a simple layout on my remote, that's all basically. – user3046061 Aug 21 '14 at 15:43
  • @user3046061: and you'll get a simple layout, if you ignore the autogenerated stuff. Seriously, copy-paste the `.gitignore` I linked and you should be good to go -- no need to "whitelist" your source code files. (The former is also better practice, for when you want to make more complex programs). – nneonneo Aug 21 '14 at 15:46
  • That gitignore you linked seems more all encompassing than what I was using for C# so I'll use it around. Thanks. – user3046061 Aug 21 '14 at 15:52