Currently Available: Need a skilled Software Developer for your next project?
Categories
Laravel PHP

Undo composer update

You ran composer update when you meant to run composer install, and now your dependencies are all over the place. Here's how to fix it.

Standard Laravel Project

If you're not using Sail:

# Delete current state
rm -rf vendor/
rm composer.lock

# Get the old lock file from git
git checkout composer.lock

# Reinstall everything based on this old lock file
composer install

Laravel Sail Project

If you're using Sail, there's a catch: Sail lives in your vendor directory! When you delete vendor/, you can't use sail composer install anymore. Here's how to fix it:

# Delete current state
rm -rf vendor/
rm composer.lock

# Get the old lock file
git checkout composer.lock

# Run composer install via Docker directly
docker run --rm \
    -u "$(id -u):$(id -g)" \
    -v "$(pwd):/var/www/html" \
    -w /var/www/html \
    laravelsail/php83-composer:latest \
    composer install --ignore-platform-reqs

Replace php83 in laravelsail/php83-composer:latest with your PHP version:

  • PHP 7.4: laravelsail/php74-composer:latest
  • PHP 8.0: laravelsail/php80-composer:latest
  • PHP 8.1: laravelsail/php81-composer:latest
  • PHP 8.2: laravelsail/php82-composer:latest
  • PHP 8.3: laravelsail/php83-composer:latest

After this runs, Sail will be back in your vendor directory and you can use it normally again.

Already Committed the Wrong composer.lock?

If you already committed the unwanted composer.lock changes, you need to get back the old version first:

# Show the commit history of composer.lock
git log composer.lock

# You'll see something like:
# commit 123abc... (HEAD -> main) Bad update from yesterday
# commit 456def... Good state from last week
# commit 789ghi... Even older changes

# Get back the old version using the 'good' commit hash
git checkout 456def composer.lock

# Then continue with the steps above for your case (Sail or non-Sail)
What I'm building

Delegate tasks. Get software.

Give Vroni a GitHub issue, bug report, spec, or rough idea. It reads the repo, plans the change, writes code, runs checks, and works toward a review-ready pull request.

Take a look at vroni.com

Subscribe to my newsletter

Get new posts when I publish them.

I respect your privacy. Unsubscribe at any time.

Leave a Reply

Your email address will not be published. Required fields are marked *