3

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).

ComFreek
  • 29,044
  • 18
  • 104
  • 156

1 Answers1

3

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 beneath Config, 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 Config and tmp exist 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 Config and tmp containing 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).

Will Vousden
  • 32,488
  • 9
  • 84
  • 95
  • Unfortunately, CakePHP does not create the essential tmp directories and config files. Is there no way for telling Git that it should commit these files once and that it should ignore any further file changes? – ComFreek Dec 26 '12 at 14:24
  • Not as far as I know. Why do you want to do this? – Will Vousden Dec 26 '12 at 14:25
  • The problem is that if someone would clone my repo, he won't get the *Config* directory thus he has to copy & paste the essential files from another source. But at the same time, I don't want to commit my personal/local changes to all files. I've found `git update-index --assume-unchanged` here on SO ([answer link](http://stackoverflow.com/a/761116/603003)), is this what I'm looking for? – ComFreek Dec 26 '12 at 14:35
  • Thanks for the update which led me to the right *.gitignore and file name modifications! I've included them in the question body. – ComFreek Dec 26 '12 at 15:14