samwyse
samwyse

Reputation: 2996

How to use a version tracker only for certain subdirectories?

I may be looking at the wrong tool for this, but I have a system that has configured like this: $HOME/module/submodule/{bin,config,log,tmp}, on multiple servers. I would like to add source control to all of the config directories, and none of the others (especially log!). I'm guessing that I could point git at $HOME and use .gitignore to exclude everything I'm not interested in, but new modules can get added from time to time, meaning a lot of stuff I'd want to immediately exclude. Any ideas? Am I missing something obvious? BTW, I'm not married to git, I'd accept any system that meets my needs. A central change repository would be nice but isn't a requirement; I just want a way to roll-back mistakes, and also add some change tracking.

Upvotes: 0

Views: 71

Answers (2)

Lazy Badger
Lazy Badger

Reputation: 97292

Dumb and obvious way

Create repository with %REPO-ROOT at $HOME (as you think), ignore all files (syntax is VCS-dependent) before adding anything in repo, add by hand only needed files into repo

Slightly different version: ignore all except PATH/TO/config dirs (it's theoretically possible with Negative Lookahead in Mercurial, the same technique under the different name exist in Git also, AFAICR), on debug stage hg-isignored extension (source on BitBucket) will be extremely useful - for Mercurial's regexp

More nice'n'easy way

Create repository with %REPO-ROOT at each $HOME/module/submodule/config and ignore nothing (?). Link all small repos in super-repo with Git's submodules|subtrees, Mercurial's subrepos or just use multiple remotes and branches in local repo (aggregation of LIVE-repositories)


Final note

Forget about RCS (also CVS, Monotone, Bazaar, ClearCase, Rational Team Concert), don't buy headache

Upvotes: 1

skypjack
skypjack

Reputation: 50550

.gitignore is a quite powerful way to do that.

If you want to exclude everything also in the future and have no dirs or files automatically added, but a few directories already present, you can use the * pattern and ! prefix.

It follows an example of a .gitignore to put in your root directory:

# exclude files in the root dir
/*
# exclude dirs in the root for
/**/
# include back the dirs below mentioned
!/bin/
!/config/
!/tmp/

Note. Sorry, but I'm not at my laptop and I cannot try it, so I'm writing the example out of my head. Look at the documentation for any detail.

Upvotes: 2

Related Questions