如何为PrestaShop 1.7创建.gitignore文件以适配开发与生产环境
Setting up a Proper
.gitignore for PrestaShop 1.7 (Dev & Prod) Hey there! Keeping your PrestaShop 1.7 repo clean and focused on what matters—your custom code, themes, and modules—is key to smooth version control across dev and production environments. Below is a tailored setup, plus pro tips to make it work for your workflow.
Core Rules (Applies to Both Dev & Prod)
These are non-negotiable—they exclude files that are auto-generated, contain sensitive data, or shouldn’t be shared across environments:
config/settings.inc.php# Stores DB credentials, API keys, and sensitive configs (never commit this!)var/cache/**# Smarty, Doctrine, and system cache filesvar/logs/**# Error logs and debug recordsvar/sessions/**# User session data (unique to each environment)img/uploads/**# User-uploaded product images, banners, and mediadownload/**# Auto-generated PDFs, invoices, and downloadablesinstall/**# Installer files (only needed once setup is complete)admin*/**# Custom admin panel directory (adjust if you use a fixed admin folder name)modules/*# Ignore all third-party modules!modules/your-custom-module-name/# Exclude your custom modules (repeat for each one)themes/*# Ignore all third-party themes!themes/your-custom-theme/# Exclude your custom theme(s)vendor/**# Composer dependencies (teammates can install viacomposer install)
Development Environment Additions
Add these to ignore IDE-specific clutter, local debug tools, and temporary dev artifacts:
.idea/# IntelliJ/PyCharm config files.vscode/# VS Code workspace settings.DS_Store# Mac system filesThumbs.db# Windows system files.phpunit.result.cache# PHPUnit test cachephpunit.xml.local# Local PHPUnit config overrides.env.local# Local environment variables (if you use env files)
Production Environment Additions
For production, exclude extra files that don’t belong in your version-controlled repo:
*.sql# Database backup files*.zip# Site backup archivestmp/**# Temporary files generated by plugins or scriptsmaintenance.html# Custom maintenance mode page (if you don’t want to track it)
Full Example .gitignore
Here’s how to combine all these rules into one file:
# Core PrestaShop 1.7 Ignore Rules config/settings.inc.php var/cache/** var/logs/** var/sessions/** img/uploads/** download/** install/** admin*/** modules/* !modules/your-custom-module/ themes/* !themes/your-custom-theme/ vendor/** # Dev Environment Only .idea/ .vscode/ .DS_Store Thumbs.db .phpunit.result.cache phpunit.xml.local .env.local # Production Environment Only *.sql *.zip tmp/** maintenance.html
Pro Tips
- Fix Already Tracked Files: If you’ve accidentally committed files like
settings.inc.php, remove them from Git (without deleting locally) with:
Commit this change along with your newgit rm --cached config/settings.inc.php.gitignore. - Personalize Without Breaking the Repo: For team members with unique local setups, use
.gitignore.local(add this to your main.gitignore) orgit/info/excludeto keep personal ignores out of the shared repo. - Update as You Build: Whenever you add a new custom module or theme, remember to add an exclusion line (like
!modules/new-custom-module/) to avoid it being ignored.
内容的提问来源于stack exchange,提问作者josedaian
相关产品推荐
相关产品推荐

