Skip to content

Instantly share code, notes, and snippets.

@LazerPanther
Forked from webmozart/.gitattributes
Created December 2, 2015 22:49
Show Gist options
  • Save LazerPanther/50b0c792b5de9784c911 to your computer and use it in GitHub Desktop.
Save LazerPanther/50b0c792b5de9784c911 to your computer and use it in GitHub Desktop.
Automatically replacing variables in PHP files when doing "git add"
*.php filter=subvars
%%PackageName%%=My Project
%%CopyrightHolder%%=Me <me@gmail.com>
  1. Place .gitattributes in your home directory

  2. Add .gitvars to your project directory and customize it

  3. Execute:

     git config --global core.attributesfile ~/.gitattributes
     git config --global filter.subvars.clean 'php -r "echo file_exists(\".gitvars\") ? strtr(file_get_contents(\"php://stdin\"), parse_ini_file(\".gitvars\")) : file_get_contents(\"php://stdin\");"'
    
  4. Set up your IDE to create new PHP files similar to template.php

  5. Enjoy ;)

ATTENTION: One caveat of a filter on *.php files is that checkouts of branches with many PHP files become quite slow. I had to disable the filter again for this reason.

<?php
/*
* This file is part of the %%PackageName%% package.
*
* (c) %%CopyrightHolder%%
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment