Hopefully this’ll remind me how to do it rather than wasting another 20 mins!

To use a regular expression to only match a string, if it in not preceeded by a certain string, you can use a negative lookbehind assertion.

Given an input set of:

  • Object
  • RSObject
  • NSObject
  • Test RSObject

We want to find Object only if it isn’t preceeded by RS.

Solution:

(?<!RS)Object

What are Sparse Checkouts?

If you have a git repo that you have cloned to your local machine, but, there are certain files/folders that you don’t want to see – but, you don’t want to remove them from the repo – you can use sparse checkouts.

Sparse Checkouts have to be explicity enabled for each repo. And, after using them for the first time today, there seem to be some quirks that I can hopefully help you from experiencing.

I’m using a Mac 10.9.2, with Git Version: 1.8.3.4 (Apple Git-47).

How To use Sparse Checkouts?

Enable:

First you need to enable them for your repo. In your repo use:

git config core.sparseCheckout true

Next, you need to set up your includes/excludes – each entry is on a separate line in a file called ‘.git/info/sparse-checkouts’. For includes, you can use wildcard or specify the specific file/folder. For excludes, you do the same but start with a ‘!’. Unfortunately, there seem to be some quirks with this, especially with folder excludes. After a lot of trial and error, I came up with the following.

cd $GIT_DIR
echo "/*" > .git/info/sparse-checkout
echo "!server/" >> .git/info/sparse-checkout
git read-tree -mu HEAD

This will includes all files/folder in the root, except for the ‘server’ folder which is hidden.

SubModules:

You can also do this for submodules, the difference being that you need to specify those in a different sparse-checkout file (one for each submodule):

cd $GIT_DIR
echo "/*" > .git/modules/<MODULEPATH>/info/sparse-checkout
echo "!server/" >> .git/modules/<MODULEPATH>/info/sparse-checkout
git read-tree -mu HEAD

Disable:

First you have to remove any sparse-checkout settings, then, you can disable them.

echo "/*" > .git/info/sparse-checkout
echo "/*" > .git/modules/<MODULEPATH>/info/sparse-checkout  
git read-tree -mu HEAD
git config core.sparseCheckout false

Hope this helps.