我应该将 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
Should I add Laravel vendor directory to .gitignore or not?
提问by Ahmad Mobaraki
I'm having my vendor directory in .gitignore
file.
Every time I run composer update
, git can not track vendor
directory 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 update
so 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.lock
file 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 install
to 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 install
again.
您可以运行composer install
以自动安装来自composer.lock
. 由于它将被版本化,您始终可以将其回滚到工作版本并composer install
再次运行。
Side note: composer dump-autoload
shouldn't make any destructive changes in vendor
.
旁注:composer dump-autoload
不应在vendor
.
回答by Alexey Mezenin
vendor
directory is in .gitignore
by default. And this is a good idea, because composer
will install all packages it will find in composer.json
for you on any machine at any time. If you have trouble with new version of some package, just change it back in composer.json
and run composer update
again.
vendor
目录在.gitignore
默认情况下。这是一个好主意,因为composer
它会composer.json
随时在任何机器上安装它会为您找到的所有软件包。如果您在使用某些软件包的新版本时遇到问题,只需将其改回composer.json
并composer update
再次运行即可。
Of course you can remove vendor
directory from .gitignore
but this will slow down commits and will use much more disk and GitHub/BitBucket space etc.
当然,您可以从中删除vendor
目录,.gitignore
但这会减慢提交速度,并且会使用更多磁盘和 GitHub/BitBucket 空间等。