skip to Main Content

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


  1. 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.

    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search