简体   繁体   English

.gitignore无法正常工作

[英].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. 我正在运行一个网站,并部署了Git进行文件版本控制,以跟踪已编辑的文件...我注意到,甚至缓存文件也被推送到了我不想要的Gitlab上。

I created a .gitignore file and put a line like this: 我创建了一个.gitignore文件,并输入如下代码:

/app/cache/dev/smarty/compile/* /应用/缓存的/ dev /智者/编译/ *

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 现在,每次执行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

it's a long list, how to stop pushing those file by ignoring them, I might forgot to do something? 这是一个很长的清单,如何通过忽略它们来停止推送这些文件,我可能忘了做点什么?

Adding files to .gitignore does not remove them from the repository. 将文件添加到.gitignore不会将其从存储库中删除。 It just prevents git add from adding these files as new files. 它只是防止git add将这些文件添加为新文件。

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. 因此,在将/app/cache/dev/smarty/compile/*.gitignore ,您还必须从存储库中删除这些文件,最好不要从文件系统中删除它们,以免破坏您的网站。

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. 为此,您可以执行git rm --cached -r app/cache/dev/smarty/compile/* ,检查结果是否仅删除要删除的文件并提交。

First, you need to update your .gitignore to match all sub-directories of /app/cache/dev/smarty/compile by removing the trailing asterisk. 首先,您需要通过删除结尾的星号来更新.gitignore以匹配/app/cache/dev/smarty/compile的所有子目录。

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 . 您可以通过运行git rm -r app/cache/dev/smarty/compile Once they are removed from your branch, they should not appear anymore when running git status . 从分支中删除它们后,在运行git status时不应再显示它们。

This is a description of gitignore pattern format: https://git-scm.com/docs/gitignore#_pattern_format 这是gitignore模式格式的描述: https ://git-scm.com/docs/gitignore#_pattern_format

In your case /app/cache/dev/smarty/compile/ without asterics should work. 在您的情况下,/ app / cache / dev / smarty / compile /不带星号应该可以工作。

But gitignore won't help once your files are tracked (if they are in modified section this means that they are tracked). 但是一旦跟踪文件,gitignore将无济于事(如果它们在修改的部分中,则意味着它们已被跟踪)。 This answer should help you to remove them from tracked: Remove a folder from git tracking 此答案应帮助您从跟踪中删除它们: 从git跟踪中删除文件夹

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM