为什么 git 在 vendor 目录中查找?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18748942/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 09:03:15  来源:igfitidea点击:

Why is git looking inside vendors directory?

rubygitgitignore

提问by Manolo

I have the .gitignore file with this code:

我有带有以下代码的 .gitignore 文件:

/app/cache/*
/app/logs/*
/app/bootstrap*
/vendor/*
/web/bundles/
/app/config/parameters.yml

but when I do :

但是当我这样做时:

$ git status

in any situation (before and after add and commit), I get a long text output like this:

在任何情况下(在添加和提交之前和之后),我都会得到一个长文本输出,如下所示:

    ...

    #   deleted:    vendor/doctrine/orm/tools/sandbox/cli-config.php
    #   deleted:    vendor/doctrine/orm/tools/sandbox/doctrine
    #   deleted:    vendor/doctrine/orm/tools/sandbox/doctrine.php
    #   deleted:    vendor/doctrine/orm/tools/sandbox/index.php
    #   deleted:    vendor/doctrine/orm/tools/sandbox/xml/Entities.Address.dcm.xml
    #   deleted:    vendor/doctrine/orm/tools/sandbox/xml/Entities.User.dcm.xml
    #   deleted:    vendor/doctrine/orm/tools/sandbox/yaml/Entities.Address.dcm.yml
    #   deleted:    vendor/doctrine/orm/tools/sandbox/yaml/Entities.User.dcm.yml
    #   modified:   vendor/friendsofsymfony/user-bundle/FOS/UserBundle
    #   modified:   vendor/gedmo/doctrine-extensions
    #   modified:   vendor/herzult/forum-bundle/Herzult/Bundle/ForumBundle
    #   modified:   vendor/kriswallsmith/assetic
    #   modified:   vendor/symfony/property-access/Symfony/Component/PropertyAccess/.gitignore
    #   modified:   vendor/symfony/property-access/Symfony/Component/PropertyAccess/StringUtil.php
    #   modified:   vendor/symfony/symfony/CHANGELOG-2.1.md

    ...

The vendors directory is in .gitignore file, so I don't know what is happening. I've tried with:

供应商目录在 .gitignore 文件中,所以我不知道发生了什么。我试过:

$ sudo git clean -dxf

but nothing changes.

但没有任何变化。

回答by u1860929

Your vendor directory is checked in to the repo. To remove it, go to your git repo root and run:

您的供应商目录已签入存储库。要删除它,请转到您的 git repo 根目录并运行:

git rm -r --cached vendor

This will recursively (due to -rflag) remove vendor from your git repo. The --cachedflag will keep the local copy of vendor directory in tact. Note that if there are other devs working with the repo, their copy of the vendordirectory will be removed and they will need to bundle installagain.

这将递归地(由于-r标志)从您的 git 存储库中删除供应商。该--cached标志将保持供应商目录的本地副本完好无损。请注意,如果有其他开发人员使用该存储库,他们的vendor目录副本将被删除,他们将需要bundle install再次删除。

Once you've untracked the directory in git, you can commit the change using:

在 git 中取消跟踪目录后,您可以使用以下命令提交更改:

git commit -m "untrack vendor directory"

Thereafter, .gitignorewill happily ignore any changes within the vendor directory next time onwards.

此后,.gitignore下次将很乐意忽略供应商目录中的任何更改。

Also, you don't need your entries in .gitignoreto begin with a /. Use the /when you want to ensure that only files/folders in root directory are ignored, and any file in a subdirectory matching the pattern should not be ignored.

此外,您不需要输入.gitignore/. 使用/时要确保只有文件/根目录下的文件夹都将被忽略,并且在子目录匹配任何文件的模式不应该被忽视。

回答by Slaven Rezic

It looks like you already have files under vendor/* checked in. .gitignoreignores only untracked files. See also the first paragraph in man gitignore.

看起来您已经在 vendor/* 下签入.gitignore了文件。仅忽略未跟踪的文件。另请参阅 中的第一段man gitignore