I’ve just downloaded (not cloned!) CakePHP 2.2.4.
The directory containains a .gitignore file:
# only the relevant part here
/app/Config
/app/tmp
Now I executed these command because the directories (and their initial contents) Config and tmp would otherwise never been committed:
git add -f Config
git add -f tmp
I have no problems with the tmp directory because no files are changed there, only new files will be created!
In contrast, I had to modify some files (e.g. database configuration) in the Config folder.
But Git now wants me to git add these modified files again!
How can I ignore these modifications?
I could also reinit the whole Git repo because I didn’t created/modified too much.
My modifications to CakePHP for solving the actual problem
My new *.gitignore file for CakePHP:
# removed: /app/Config/
# start edit
/app/Config/*
!/app/Config/Schema/
!/app/Config/*.default.php
# end edit
/app/tmp
/lib/Cake/Console/Templates/skel/tmp/
/plugins
/vendors
/build
/dist
.DS_Store
/tags
I’ve also suffixed all files in /app/Config with .default:
-
acl.ini.default.php.
-
acl.default.php.
-
bootstrap.default.php.
-
core.default.php.
-
database.php.default –> database.default.php
-
email.php.default –> database.default.php
Edit: It’s better to have *.default.php than *.php.default because this prevents outputting the file to the browser if mod_rewrite fails (though that’s very unlikely).
Git does not track directories; only files. So when you run
git add -f Config, git is simply adding all files in the working tree beneathConfig, not the directory itself. Since these files are then tracked by Git (thus overriding the ignore rules), changing them will cause Git to consider the working tree dirty.These rules for
Configandtmpexist in CakePHP’s .gitignore file because the entire directory can effectively be ignored by Git; there’s no need to explicitly create empty directories, since CakePHP will presumably create them automatically.If for some reason you want Git to know that there should be a directory there, but to ignore its contents, then you can add a .gitignore file inside
Configandtmpcontaining the the rule*, which will tell it to ignore everything iside that directory. Since the .gitignore file is there, however, it’ll maintain the directory itself.Update: If you want to store a “default” config in Git that is to be customised on a per-working-copy basis, you’re better off committing a template config file under a different name that can be copied to a new (ignored) file when the repository is cloned and populated with environment-specific config options.
As I see it, the config files themselves shouldn’t be kept under version control, since they need to be tailored to the environment in which the working copy is being used, so keeping template copies in this way seems the natural solution (this is what WordPress does).