Would reset hard uninstall a package?
Say I have commits
789f658a6e55a65cc3f056asf – Commit before installing package
789fdfdsfse55a65cc3f056asf – Commit after installing package
If I reset to “Commit before installing package” would that uninstall the package or just remove the line in composer json?
What is the right way of uninstalling the package?
When I reset hard it looks the package is still not uninstalled though I could no longer see it in composer.json
2
Answers
Git itself knows nothing about Composer, or even PHP. What gets rolled back when you checkout a commit, reset, etc, depends entirely on what files you commit.
In Composer, there are three places where a package ends up:
composer.json
. This is the file you edit by hand. It tells Composer what packages you depend on, and what the minimum and maximum versions it’s allowed to use, but not the specific version installed.composer.lock
. This is the file that Composer generates when you runcomposer update
(and some other commands). It lists exact versions of every package installed, including indirect dependencies (packages needed by other packages, rather than listed directly in yourcomposer.json
).vendor
directory. These are the files PHP will actually execute.As the Composer documentation explains for a standalone project, you should normally commit both composer.json and composer.lock, but not
vendor
. This allows you to install the exact same versions each time you switch branch, deploy to a new server, etc, by runningcomposer install
.If this is what you’ve done, then by resetting to or checking out the commit before you updated the package, you will get your old
composer.lock
, but git won’t touch yourvendor
directory.To actually install the packages listed in that
composer.lock
, you would runcomposer install
. That will make the content of yourvendor
directory match the exact versions listed incomposer.lock
, including uninstalling things which aren’t listed there.The easy way:
you can remove any package from your project by run this command (if you use composer):
The complex way:
remove the package lines from composer.json
remove the package from config/bundles.php
run
composer install