A student in my MCAD PHP and WordPress class ran into a curious issue where her changes to PHP scripts running in MAMP weren’t reflected when she refreshed the page in a browser, unless she opened the page in a new tab. Turns out OPcache is enabled by default in PHP 5.5.3 running in MAMP 2.2. Here’s a Stack Overflow post on how to disable it in your php.ini file.
- Find your php.ini file. In my MAMP installation it was located at: /Applications/MAMP/bin/php/php5.5.3/conf/php.ini.
- Comment out the OPcache lines at the bottom by putting a semicolon in front:
Stop and start your MAMP servers.
This is not a common situation, but occasionally you may find yourself having force-committed a bunch of things (usually a bad sign to begin with, but that’s a whole ’nother post) and a few files that should be ignored sneak into your repo. You might have dozens of commits from that point on and not be aware of it, because your .gitignore file dutifully doesn’t track those files anyway.
So: how to remove those files from the Git cache? My research led me to rewriting commits, which is usually filed in the “Contents Dangerous. Open With Caution.” section of Git. Here’s some links:
So here was my process:
- Remove the files from the Git cache. I used an rm -rf command because I was getting rid of directories. For example:
git filter-branch --index-filter 'git rm -rf --cached --ignore-unmatch <path to file or directory, from root level of your repo>' HEAD
- Prune Git. For example:
rm -rf .git/refs/original/ && git reflog expire --all && git gc --aggressive --prune
- Force-push your edits, otherwise they will be rejected because you’ve rewritten history. (Couldn’t figure this part out until I read Thomas Hunter’s post linked above.)
git push origin master --force
If you’ve got a bunch of files, I would suggest atnan’s gist linked above, or David Underhill’s script (second link). David’s script also prunes Git (my understanding is you can still have file references hanging around that need to be garbage-collected).
Ideally you would never end up in this situation, and hopefully you catch this before you’ve pushed changes to a remote and others have pulled the dirty repo down. In my case there didn’t seem to be ill effects introduced by rewriting commits and pushing to a remote, but it’s something I’d like to avoid as much as possible.
Drupal has a Features module which allows for certain configuration settings (Views/Context/Content Types) to be exported to code. This way you can separate out configuration from content, and avoid having to sync databases up/down environments.
Except that sometimes (in my experience) you hit a wall with a created feature. I’m not sure where that limit is, but sometimes you end up with a feature that simply won’t allow you to re-create it cleanly.
In those cases my workaround has been to simply export just the specific component that changed, and then hand-merge the code myself. This can be troublesome if you have a lot of components, however.
(That’s maybe 1/20th of the checkboxes for this feature. Which is a lot of clicking.)
So here’s a quick line of jQuery you can run in your browser console to uncheck every component in your features module.
I’ve also put this up as a gist.