.gitignore无法正常工作

时间:2018-05-19 19:00:35

标签: git gitignore

我正在运行一个网站,我部署了Git进行文件版本控制以跟踪已编辑的文件......我注意到即使缓存文件也被推送到我不想要的Gitlab。

我创建了一个.gitignore文件并放了这样一行:

/应用/高速缓存的/ dev /智者/编译/ *

我添加了它,承诺并推动它,生命是美好的。

现在,每次我这样做:git status,我看到这些文件被修改为浏览缓存

 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

这是一个很长的清单,如何通过忽略它们来停止推送这些文件,我可能忘记做某事了?

3 个答案:

答案 0 :(得分:4)

将文件添加到.gitignore不会将其从存储库中删除。它只是阻止git add将这些文件添加为新文件。

因此,在将/app/cache/dev/smarty/compile/*添加到.gitignore之后,您还必须从存储库中删除这些文件,最好不要将它们从文件系统中删除,以免破坏您的网站。

为此,您可以执行git rm --cached -r app/cache/dev/smarty/compile/*,检查结果,它只删除您要删除的文件并提交。

答案 1 :(得分:0)

首先,您需要通过删除尾随星号来更新.gitignore以匹配/app/cache/dev/smarty/compile的所有子目录。

然后,您需要清理已在分支的早期提交中添加到存储库的文件。您可以通过运行git rm -r app/cache/dev/smarty/compile来执行此操作。将它们从您的分支中删除后,在运行git status时不应再出现它们。

答案 2 :(得分:0)

这是gitignore模式格式的描述:https://git-scm.com/docs/gitignore#_pattern_format

在你的情况下/ app / cache / dev / smarty / compile /没有星号应该可以工作。

但是,一旦您的文件被跟踪,gitignore就会获得帮助(如果他们处于修改部分,这意味着他们被跟踪)。此答案可以帮助您将其从跟踪中移除:Remove a folder from git tracking

相关问题