.gitignore仍在跟踪文件,即使我试图忽略它们,为什么?

时间:2017-02-24 14:47:04

标签: git github gitignore

我在项目中有以下目录结构:

.
├── application
│   ├── ... <more folders & files goes here>
├── config
├── cronjobs
│── ... <more folders & files goes here>
├── oneview_symfony
│   ├── app
│   ├── bin
│   ├── src
│   ├── tests
│   ├── var
│   ├── vendor
│   └── web
├── .gitignore

我试图忽略一些文件和文件夹,这是我在.gitignore文件中的规则:

oneview_symfony/app/cache/*
oneview_symfony/app/logs/*
!oneview_symfony/app/cache/.gitkeep
!oneview_symfony/app/logs/.gitkeep

oneview_symfony/app/spool/*

oneview_symfony/var/cache/*
oneview_symfony/var/logs/*
oneview_symfony/var/sessions/*
!oneview_symfony/var/cache/.gitkeep
!oneview_symfony/var/logs/.gitkeep
!oneview_symfony/var/sessions/.gitkeep

oneview_symfony/app/config/parameters.yml
oneview_symfony/app/config/parameters.ini

oneview_symfony/app/bootstrap.php.cache
oneview_symfony/var/bootstrap.php.cache
oneview_symfony/bin/*
!oneview_symfony/bin/console
!oneview_symfony/bin/symfony_requirements
oneview_symfony/vendor/*

oneview_symfony/web/bundles/
oneview_symfony/web/uploads/   
oneview_symfony/app/phpunit.xml
oneview_symfony/phpunit.xml
oneview_symfony/build/

oneview_symfony/web/css/
oneview_symfony/web/js/

如果我运行git status,我会看到上面的信息,我仍然会看到oneview_symfony/vendor/下的文件,为什么?我缺少什么?

上述命令的输出示例:

    ...
    new file:   oneview_symfony/vendor/zendframework/zendframework1/resources/languages/pt_BR/Zend_Validate.php
    new file:   oneview_symfony/vendor/zendframework/zendframework1/resources/languages/ru/Zend_Validate.php
    new file:   oneview_symfony/vendor/zendframework/zendframework1/resources/languages/sk/Zend_Captcha.php
    new file:   oneview_symfony/vendor/zendframework/zendframework1/resources/languages/sk/Zend_Validate.php
    new file:   oneview_symfony/vendor/zendframework/zendframework1/resources/languages/sr/Zend_Validate.php
    new file:   oneview_symfony/vendor/zendframework/zendframework1/resources/languages/uk/Zend_Validate.php
    modified:   oneview_symfony/web/.htaccess

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

1 个答案:

答案 0 :(得分:2)

您已将这些文件添加到git仓库中和/或暂存更改。

要从repo中删除它们,您可以运行git rm -r --cache <folder-to-ignore>将它们从git缓存中删除。 (确保包含--cache标志,以便它也不会删除实际文件!)

如果您只是暂存文件,则可以运行git reset来取消暂存,如果已将这些文件正确添加到.gitignore,它们应停止显示在更改列表中。< / p>