user9816704
user9816704

Reputation:

.gitignore is not working properly

I'm running a website and I deployed Git for file versioning to keep track of edited files... I noticed that even cache files are pushed to Gitlab which I don't want.

I created a .gitignore file and put a line like this:

/app/cache/dev/smarty/compile/*

I added it, committed and pushed it, Life is beautiful.

Now, everytime I do : git status, I see these files as modified which are browsing cache

 modified:   app/cache/dev/smarty/compile/00/7c/14/007c1437400d132932e061d38915162f50f3b8d7.file.ApProductList.tpl.php
    modified:   app/cache/dev/smarty/compile/11/0e/c7/110ec72aa9921d2c382ad628bdb2f0bc5105a617.module.ps_searchbar.tpl.php
    modified:   app/cache/dev/smarty/compile/14/cf/62/14cf62b857ae9d1a45052e93e4a5f7744c543c46.file.ApMegamenu.tpl.php
    modified:   app/cache/dev/smarty/compile/15/9c/65/159c651fcb923e7ff3efcd17bc6356e6f77d1032.file.leoslideshow.tpl.php
    modified:   app/cache/dev/smarty/compile/18/2a/ea/182aea6706a2d4ae5bfc3f6d3a5b33417c49b6af.module.notification.tpl.php
    modified:   app/cache/dev/smarty/compile/24/41/64/24416476c1e4c535f73ed4c66a125c0e880f294b.file.leo_list_product_review.tpl.php
    modified:   app/cache/dev/smarty/compile/30/7d/c6/307dc6bd4724d29d1572cc301dd7148e962604ef.module.ps_emailsubscription.tpl.php
    modified:   app/cache/dev/smarty/compile/32/74/ea/3274eac0d659ac48de29176349457a485f0a7846.file.ApBlockLink.tpl.php
    modified:   app/cache/dev/smarty/compile/35/65/5e/35655e6409b6198f29dd6e732ef9598dec599880.module.ps_shoppingcart.tpl.php
    modified:   app/cache/dev/smarty/compile/38/37/a8/3837a8fdc3367fa8be15dd17f53842319311023b.file.plist1487280701.tpl.php
    modified:   app/cache/dev/smarty/compile/39/e1/75/39e175b351bd73dee402d5a54877d3be6344bbe4.file.leo_cart_button.tpl.php
    modified:   app/cache/dev/smarty/compile/3b/2b/08/3b2b08f3e7cd22b2aad86e184d6bdfdc8b3802cf.module.modal.tpl.php
    modified:   app/cache/dev/smarty/compile/43/80/cd/4380cd32bf825479f4e58e8f1a26818a8f607913.file.ApHtml.tpl.php
    modified:   app/cache/dev/smarty/compile/51/3e/9c/513e9ce13e7d8790fecede8bcf00cdc8ca0ef171.file.slidecaptcha-header.tpl.php
    modified:   app/cache/dev/smarty/compile/5a/51/17/5a5117cf6d0e1dffe864e8c6e12c7c631b3df555.file.ApColumn.tpl.php
    modified:   app/cache/dev/smarty/compile/5e/b2/05/5eb205658affb81ad209afd041b5ce7f724c9288.file.appagebuilder.tpl.php
    modified:   app/cache/dev/smarty/compile/75/be/84/75be842c1b804d7817967aceea1b33cc9f212c84.file.ApModule.tpl.php
    modified:   app/cache/dev/smarty/compile/80/5c/e2/805ce2d86f1187d802d55b829fd8b831e391ad7c.module.fly_cart.tpl.php
    modified:   app/cache/dev/smarty/compile/80/ac/9d/80ac9ddb06fe7b43ffdd2f5cd1185536480d2577.module.ps_socialfollow.tpl.php
    modified:   app/cache/dev/smarty/compile/8d/87/67/8d87672f84fea39023a026ec3e77c50d0205b84a.file.megamenu.tpl.php
    modified:   app/cache/dev/smarty/compile/94/3d/87/943d870759e124a38846d736284d297b82268471.file.ApSlideShow.tpl.php
    modified:   app/cache/dev/smarty/compile/97/9d/97/979d976ed6034e059eef22b8e951012b4262674e.file.ApManuFacturersCarousel.tpl.php
    modified:   app/cache/dev/smarty/compile/99/f1/47/99f147cdc5f8fa7776be7f182bac4542c4e7954c.file.ApProductCarousel.tpl.php
    modified:   app/cache/dev/smarty/compile/9d/30/9b/9d309b84d5f56fc52e6632a8d91893c2f5a67658.file.javascript_parameter.tpl.php

it's a long list, how to stop pushing those file by ignoring them, I might forgot to do something?

Upvotes: 2

Views: 326

Answers (3)

Pierre
Pierre

Reputation: 1099

First, you need to update your .gitignore to match all sub-directories of /app/cache/dev/smarty/compile by removing the trailing asterisk.

Then, you need to clean up the files that have already been added to the repository in earlier commits of the branch. You can do so by running git rm -r app/cache/dev/smarty/compile. Once they are removed from your branch, they should not appear anymore when running git status.

Upvotes: 0

Lienhart Woitok
Lienhart Woitok

Reputation: 426

Adding files to .gitignore does not remove them from the repository. It just prevents git add from adding these files as new files.

So after adding /app/cache/dev/smarty/compile/* to .gitignore, you also have to remove these files from your repository, preferably without removing them from the filesystem to not disrupt your website.

To do this, you can execute git rm --cached -r app/cache/dev/smarty/compile/*, check the result that it only removes the files you want removed and commit it.

Upvotes: 4

Ann  Sorokina
Ann Sorokina

Reputation: 171

This is a description of gitignore pattern format: https://git-scm.com/docs/gitignore#_pattern_format

In your case /app/cache/dev/smarty/compile/ without asterics should work.

But gitignore won't help once your files are tracked (if they are in modified section this means that they are tracked). This answer should help you to remove them from tracked: Remove a folder from git tracking

Upvotes: 0

Related Questions