6

I use git as my primary version control system, and have recently started using git on my CakePHP projects. This is my current .gitignore file:

app/tmp
vendors/

As used in the cakephp git repo, but this causes a bit more work for me when deploying the project to a server, because I have to go in and create all the app/tmp/ sub-directories by hand before they will work correctly. Is there a way to set it up to ignore the contents on these folders, but to still have them under git control so they appear when I clone the repo into the hoted directory?

I also have been having an issue with my git index being reset while I am working on it, which is causing me to have to do a lot more commits than should be necessary, any ideas on that also?

trobrock
  • 46,549
  • 11
  • 40
  • 46
  • Can you explain more about your problem with git index? Which steps will reproduce the problem? – Esko Luontola Feb 07 '10 at 20:02
  • You probably want the answers from http://stackoverflow.com/questions/115983/how-do-i-add-an-empty-directory-to-a-git-repository regarding how to add the directories but ignore their contents. – Jakob Borg Feb 07 '10 at 21:04
  • I am unsure of the activities that are causing the issues, but what seems to be randomly all the files in the index are shown as deleted, then I have to re-add all the files to the index. – trobrock Feb 07 '10 at 22:53

3 Answers3

11

Git stores only files, not directories, so you can for example add a hidden file into that directory and commit it.

  1. Remove app/tmp/ from .gitignore
  2. touch app/tmp/.keep
  3. git add app/tmp/.keep
  4. git commit
  5. Add app/tmp/ to .gitignore
Esko Luontola
  • 73,184
  • 17
  • 117
  • 128
4

As mentioned git only stores files, not directories. By default cake's .gitignore file ignores all contents in the tmp folder to prevent tmp files being added to your repository.

You can (and should) however do this after you create a project:

cd /my/app
git add -f tmp

which will do this:

$ git status
# On branch master
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#   new file:   tmp/cache/models/empty
#   new file:   tmp/cache/persistent/empty
#   new file:   tmp/cache/views/empty
#   new file:   tmp/logs/empty
#   new file:   tmp/sessions/empty
#   new file:   tmp/tests/empty

As such your tmp folder structure is ready to be committed, but all other files in your tmp dir will (continue to) be ignored.

AD7six
  • 63,116
  • 12
  • 91
  • 123
1

My .gitignore file.

tmp/*
[Cc]onfig/core.php
[Cc]onfig/database.php

webroot/files/
webroot/img/photos/

!empty
.DS_Store

If you'll notice I have !empty which saves me from creating .keep files all over which is so SVN ago. Lastly you'll also see that I use this config for both cakePHP 1.x and 2.x projects noted by the [Cc]. I have some folders setup that I store user files in so I always ignore them as well. Finally the .DS_Store ignores my MAC created thumbnail views for my project.

Chris Pierce
  • 706
  • 5
  • 9