【问题标题】:.gitignore is not working properly.gitignore 无法正常工作
【发布时间】:2018-10-29 21:53:48
【问题描述】:

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

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

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

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

现在,每次我这样做: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

这是一个很长的列表,如何通过忽略它们来停止推送这些文件,我可能忘了做点什么?

【问题讨论】:

标签: git gitignore


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    这是对gitignore模式格式的说明:https://git-scm.com/docs/gitignore#_pattern_format

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

    但是一旦你的文件被跟踪, gitignore 将无济于事(如果它们在修改部分,这意味着它们被跟踪)。这个答案应该可以帮助您将它们从跟踪中删除:Remove a folder from git tracking

    【讨论】:

      【解决方案3】:

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

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

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

      【讨论】:

      • 这很聪明,很有魅力!非常感谢
      • 我应该像其他人所说的那样删除星号吗?
      • 这取决于个人品味,据我所知,从技术上讲,在这种情况下没有区别。删除星号告诉 git 忽略目录及其内容,保留星号告诉 git 忽略目录中的所有文件和目录。由于 git 只跟踪文件而不跟踪目录,因此两者都会产生完全相同的一组实际被忽略的文件。
      猜你喜欢
      • 2017-09-06
      • 2016-12-01
      • 2017-07-02
      • 1970-01-01
      • 2016-09-01
      • 2012-07-11
      • 2018-04-08
      • 2017-04-20
      • 2018-10-02
      相关资源
      最近更新 更多