Home Development Tools composer Does the content downloaded by composer need to be submitted to git?

Does the content downloaded by composer need to be submitted to git?

Jun 08, 2021 pm 03:46 PM
composer

The following tutorial column of composer will introduce to you the question of whether the content downloaded by composer needs to be submitted to git. I hope it will be helpful to friends who need it!

Specific question:

I would like to ask all the students who use Composer, will you submit the content of the files downloaded through Composer to Git?
I saw the article Should I Commit the dependencies in my vendor directory on the official Faq. Some people suggested not to submit it to Git. So how should I deal with the problem of re-composer install when switching branches? If the vendor is submitted to the repository, how should the .git folder in the package be handled?

*Correction composer update should be composer install

Solution:

In fact, whether it is branch development or deployment to the production environment , no matter how you write the wildcard rules for the version number in composer.json, what we are most concerned about is always the most fundamental content: At the time of development, what is the specific version number of all the dependent libraries we used?

This content is supported by the composer.lock file. By maintaining lock files, composer itself records the specific versions of all dependent libraries in the project after any changes are made to the dependent libraries. Please read the documentation about this file (https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file).

You should always submit the composer.lock file to the repository, and after switching branches or deploying, use composer install to install the specific dependency versions specified in the lock file.

In this sense, it is correct whether you submit the vendor directory to the main repository. It is a trade-off choice whether to submit or not:

If submitted:

Advantages: "Pull and use" convenience.

Disadvantages: Duplication of information. Because of the specific version you developed at the time, the lock file has been recorded. In other words, the vendor folder expresses the same thing.

Disadvantage: Risk of introducing inconsistency. Because although Composer ensures that the lock file is consistent with the vendor directory, submitting it to the git repository is a manual act after all. You can't guarantee that you won't fall behind one of the two.

If you do not submit, the advantages and disadvantages will be reversed. Not to be repeated again.

My thoughts are: I suggest you stick to the idea of ​​"correctness over ease of use". My suggestion is not to submit to the vendor, but just use the lock file to maintain the version of the dependent library at the time of development.

If you submit, please be sure to follow the following two guidelines:

(1) Be sure to ensure that the submission of the two files vendor and composer.lock is synchronized. If one is mentioned, the other must be mentioned.
Any development, if only one of the commits is submitted, must be held accountable.
The reason for this is: Although we submit to the vendor to ensure that it is available immediately after pulling it, git has a partial checkout function - for a Composer project, I have the right to follow the convention of the Composer project and not check out vendor directory, but pull down the actual code and then do a composer install. You can't say I'm wrong.
(If anyone says this is wrong, I support you to expose your unscrupulous company and technical director on SF and Zhihu every minute)

(2) Be sure to follow Composer’s instructions for submitting the vendor folder Suggestion (https://getcomposer.org/doc/faqs/should-i-commit-the-dependencies-in-my-vendor-directory.md), ignore all .git directories of sub-library, and only submit the ones in vendor Code of practice.
Believe me, the actual code in the vendor and the management files of the git library itself under vendor/**/.git are definitely related to the above-water part and the underwater part of the iceberg. If you don't ignore it, people will die. It's not an exaggeration.

It must also be pointed out that during branch development, even if you do not synchronize the vendor through the repository, but only synchronize composer.lock, it will not cause a waste of time.

When switching between two branches, it is nothing more than switching back and forth between two specific versions. Composer itself caches all downloaded libraries. The composer install after each branch pull will definitely hit all caches, without repeatedly consuming download time.

The above is the detailed content of Does the content downloaded by composer need to be submitted to git?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to solve the complexity of WordPress installation and update using Composer How to solve the complexity of WordPress installation and update using Composer Apr 17, 2025 pm 10:54 PM

When managing WordPress websites, you often encounter complex operations such as installation, update, and multi-site conversion. These operations are not only time-consuming, but also prone to errors, causing the website to be paralyzed. Combining the WP-CLI core command with Composer can greatly simplify these tasks, improve efficiency and reliability. This article will introduce how to use Composer to solve these problems and improve the convenience of WordPress management.

Accelerate PHP code inspection: Experience and practice using overtrue/phplint library Accelerate PHP code inspection: Experience and practice using overtrue/phplint library Apr 17, 2025 pm 11:06 PM

During the development process, we often need to perform syntax checks on PHP code to ensure the correctness and maintainability of the code. However, when the project is large, the single-threaded syntax checking process can become very slow. Recently, I encountered this problem in my project. After trying multiple methods, I finally found the library overtrue/phplint, which greatly improves the speed of code inspection through parallel processing.

How to solve SQL parsing problem? Use greenlion/php-sql-parser! How to solve SQL parsing problem? Use greenlion/php-sql-parser! Apr 17, 2025 pm 09:15 PM

When developing a project that requires parsing SQL statements, I encountered a tricky problem: how to efficiently parse MySQL's SQL statements and extract the key information. After trying many methods, I found that the greenlion/php-sql-parser library can perfectly solve my needs.

How to solve complex BelongsToThrough relationship problem in Laravel? Use Composer! How to solve complex BelongsToThrough relationship problem in Laravel? Use Composer! Apr 17, 2025 pm 09:54 PM

In Laravel development, dealing with complex model relationships has always been a challenge, especially when it comes to multi-level BelongsToThrough relationships. Recently, I encountered this problem in a project dealing with a multi-level model relationship, where traditional HasManyThrough relationships fail to meet the needs, resulting in data queries becoming complex and inefficient. After some exploration, I found the library staudenmeir/belongs-to-through, which easily installed and solved my troubles through Composer.

How to solve the problem of core function expansion in TYPO3CMS project? Composer can help you! How to solve the problem of core function expansion in TYPO3CMS project? Composer can help you! Apr 17, 2025 pm 10:45 PM

When developing TYPO3CMS projects, you often encounter situations where you need to expand your core functions. As a beginner, I have struggled with how to efficiently manage and extend these core features. Fortunately, by using Composer, I found a simple and effective solution.

Use Composer to solve the problem of RSA signature algorithm in JWT framework Use Composer to solve the problem of RSA signature algorithm in JWT framework Apr 17, 2025 pm 11:09 PM

I encountered a tricky problem when developing a project that requires JWT (JSONWebToken) certification: how to implement RSA signature algorithm safely and efficiently in JWT. Although I have some understanding of JWT, I am confused about the specific implementation of the RSA signature algorithm. After some exploration, I found the web-token/jwt-signature-algorithm-rsa library, which gave me the perfect solution.

How to optimize website performance: Experiences and lessons learned from using the Minify library How to optimize website performance: Experiences and lessons learned from using the Minify library Apr 17, 2025 pm 11:18 PM

In the process of developing a website, improving page loading has always been one of my top priorities. Once, I tried using the Miniify library to compress and merge CSS and JavaScript files in order to improve the performance of the website. However, I encountered many problems and challenges during use, which eventually made me realize that Miniify may no longer be the best choice. Below I will share my experience and how to install and use Minify through Composer.

Solve CSS prefix problem using Composer: Practice of padaliyajay/php-autoprefixer library Solve CSS prefix problem using Composer: Practice of padaliyajay/php-autoprefixer library Apr 17, 2025 pm 11:27 PM

I'm having a tricky problem when developing a front-end project: I need to manually add a browser prefix to the CSS properties to ensure compatibility. This is not only time consuming, but also error-prone. After some exploration, I discovered the padaliyajay/php-autoprefixer library, which easily solved my troubles with Composer.

See all articles