To answer the question : if you want to exclude certain files of a checkout, you can use sparse-checkout
In .git/info/sparse-checkout
, define what you want to keep. Here, we want all (*) but (note the exclamation mark) config.php :
/* !/config.php
Tell git you want to take sparse-checkout into account
git config core.sparseCheckout true
If you already have got this file locally, do what git does on a sparse checkout (tell it it must exclude this file by setting the "skip-worktree" flag on it)
git update-index --skip-worktree config.php
Enjoy a repository where your config.php file is yours - whatever changes are on the repository.
Please note that configuration values SHOULDN'T be in source control :
- It is a potential security breach
- It causes problems like this one for deployment
This means you MUST exclude them (put them in .gitignore before first commit), and create the appropriate file on each instance where you checkout your app (by copying and adapting a "template" file)
Note that, once a file is taken in charge by git, .gitignore won't have any effect.
Given that, once the file is under source control, you only have two choices () :
rebase all your history to remove the file (with git filter-branch
)
create a commit that removes the file. It is like fighting a loosing battle, but, well, sometimes you have to live with that.