我应该将 Laravel 供应商目录添加到 .gitignore 中吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39192071/
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-14 14:22:41  来源:igfitidea点击:

Should I add Laravel vendor directory to .gitignore or not?

gitlaravelcomposer-phpgitignore

提问by Ahmad Mobaraki

I'm having my vendor directory in .gitignorefile. Every time I run composer update, git can not track vendordirectory updates and changes and therefor I can not backward these changes!!

我在.gitignore文件中有我的供应商目录。每次运行时composer update,git 都无法跟踪vendor目录更新和更改,因此我无法回溯这些更改!!

My question is:Is it possible that application crash OR encounter errors after composer updateso there is a need to git reset?

我的问题是:应用程序是否有可能崩溃或遇到错误,composer update所以有必要git reset吗?

If it is possible, isn't it better to remove vendor directory from .gitignore? maybe there are other solutions to this problem ? (if it is a problem at all !!)

如果可能,从 中删除供应商目录不是更好.gitignore吗?也许这个问题还有其他解决方案?(如果这是一个问题!)

回答by ceejayoz

Composer provides the composer.lockfile for this purpose.

Composer 提供了composer.lock用于此目的的文件。

Installing a new package, doing a composer update, etc. that causes package changes will write the exact versions of the installed packages to composer.lock. You should include this file in your repository's versioned files.

安装新包、执行 acomposer update等导致包更改的操作会将已安装包的确切版本写入composer.lock. 您应该将此文件包含在存储库的版本化文件中。

You can run composer installto automatically install the exact list of package versions from composer.lock. As it's going to be versioned, you can always roll it back to a working version and run composer installagain.

您可以运行composer install以自动安装来自composer.lock. 由于它将被版本化,您始终可以将其回滚到工作版本并composer install再次运行。

Side note: composer dump-autoloadshouldn't make any destructive changes in vendor.

旁注:composer dump-autoload不应在vendor.

回答by Alexey Mezenin

vendordirectory is in .gitignoreby default. And this is a good idea, because composerwill install all packages it will find in composer.jsonfor you on any machine at any time. If you have trouble with new version of some package, just change it back in composer.jsonand run composer updateagain.

vendor目录在.gitignore默认情况下。这是一个好主意,因为composer它会composer.json随时在任何机器上安装它会为您找到的所有软件包。如果您在使用某些软件包的新版本时遇到问题,只需将其改回composer.jsoncomposer update再次运行即可。

Of course you can remove vendordirectory from .gitignorebut this will slow down commits and will use much more disk and GitHub/BitBucket space etc.

当然,您可以从中删除vendor目录,.gitignore但这会减慢提交速度,并且会使用更多磁盘和 GitHub/BitBucket 空间等。