Angel
Angel

Reputation: 671

Magento - Are these files safe to include on .gitignore file?

I have a Magento 1.7 website.

Then I have auto generated files in the form:

...
media/captcha/base/ff3f35b1bbc191988318a9893282f063.png
var/cache/mage--0/mage---331_Zend_LocaleC_en_US_currencynumber_
var/session/sess_58ap4vgtog56j8ojruiurgecp0
var/report/1058813543850
...

like on the image below:

enter image description here

New files like these are auto generated all the time.

I have this website on a Git repository.

Then I want to know if in case I remove all these files that could cause the website stop working as expected. I mean, some content doesn't show up, etc.

If the media/captcha/base/* files are used just once for captcha validation then for sure I could remove those files without any problem.

If the var/cache/mage--0/* files are used as support to display some content but if they are missing and then needed they are re-auto-generated, then for sure I could remove those files without any problem.

My goal here is to know if I could add these files to the .gitignore file so I don't get new changes to commit to the website repository when it is not really necessary.

For example, in the case of images uploaded via some WYSIWYG editor, I could not add those images to the .gitingore file because if I remove those files from the repository, then on the website will be missing content on the corresponding page when installing the website on another server (downloading the Git repository to it).

This is my question

What are the Magento file patterns I should add to the .gitignore file in order to have consistency when moving a website from one server to another by downloading a Git repository?

Know this would be very helpful.

Upvotes: 1

Views: 1193

Answers (1)

VonC
VonC

Reputation: 1328692

If those files are all generate in, for instance, media/captcha/base/*, all you need to do is:

  • make sure those files are not tracked (but are still present in your local drive)

    git rm -R --cached media/captcha/base/
    
  • add the all folder to the .gitignore file

    echo /media/captcha/base/>.gitignore
    git add .gitignore
    git commit -m "ignore media/captcha/base/ folder"
    

As for the magento files to ignore, see github/gitignore/Magento.gitignore (or gitignore.io/api/magento, or gitignore.io/api/magento2)

It would involve:

#--------------------------#
# Magento Default Files    #
#--------------------------#

/app/etc/local.xml

/media/*
!/media/.htaccess

!/media/customer
/media/customer/*
!/media/customer/.htaccess

!/media/dhl
/media/dhl/*
!/media/dhl/logo.jpg

!/media/downloadable
/media/downloadable/*
!/media/downloadable/.htaccess

!/media/xmlconnect
/media/xmlconnect/*

!/media/xmlconnect/custom
/media/xmlconnect/custom/*
!/media/xmlconnect/custom/ok.gif

!/media/xmlconnect/original
/media/xmlconnect/original/*
!/media/xmlconnect/original/ok.gif

!/media/xmlconnect/system
/media/xmlconnect/system/*
!/media/xmlconnect/system/ok.gif

/var/*
!/var/.htaccess

!/var/package
/var/package/*
!/var/package/*.xml

Upvotes: 1

Related Questions