0

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

jan
  • 11
  • 2
  • That depends if you have vendor in git or not. You should share in your question which files you commit: composer.json, composer.lock, vendor directory. Add that via [edit]. – hakre Jul 25 '23 at 15:44
  • _"What is the right way of uninstalling the package?"_ - does this answer your question? https://stackoverflow.com/q/23126562/367456 (it does not necessarily answer the git part, that Q&A is about Laravel + Composer) – hakre Jul 25 '23 at 15:45
  • The `vendor` folder should not be included in `git` (in a Laravel project, the default `.gitignore` file that comes with it includes `/vendor`). Rolling back a commit will affect your `composer` files, which in turn will affect your `vendor` folder when running `composer install`, so yes, a hard reset will uninstall a package, assuming you follow up the reset with a `composer install`. – Tim Lewis Jul 25 '23 at 16:26

2 Answers2

3

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:

  • Listed in 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.
  • Listed in composer.lock. This is the file that Composer generates when you run composer 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 your composer.json).
  • Actually installed in the 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 running composer 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 your vendor directory.

To actually install the packages listed in that composer.lock, you would run composer install. That will make the content of your vendor directory match the exact versions listed in composer.lock, including uninstalling things which aren't listed there.

IMSoP
  • 89,526
  • 13
  • 117
  • 169
0

The easy way:

you can remove any package from your project by run this command (if you use composer):

composer remove <package_name>

The complex way:

remove the package lines from composer.json

remove the package from config/bundles.php

run composer install