Sina Sina - 1 month ago 10x
Git Question

Composer update has removed my changes

I am working on a Laravel application, and I ran the command

composer update
in order to install new packages I had added.

I had changed/added some files in the vendor directory before that, and those files that were added have been removed. I have not committed to my vendor directory (another mistake!), hence I can't get them back through git.

Now my questions are:

  1. What happens when
    composer update
    is ran?

  2. Why the files removed are not in the Recycle Bin, what has
    happened to them? Permanently deleted?

As well, I am well aware that I can roll back my composer update, but that will not give me back my modified files, it would rather install the original files of the previous version.

Please do let me know if there is any other way (even file recovery) would help me to get these changes back.

  1. composer update looks for new versions of installed dependencies and, if found, installs new versions instead of the old ones. It doesn't care whether any changes were made to installed dependencies, because it's looking just at their descriptions stored in the composer.lock file.
  2. The files most likely cannot be recovered with composer for reasons mentioned above. You can try looking for lost files inside the cache directory .composer/cache, but I see no reason whatsoever for the lost files to be there. Yes, they are probably permanently deleted and, if those are critical, you should look for a file recovery program.

You definitely shouldn't store any modifications made to dependencies for the mentioned reasons.

Also, you probably shouldn't add vendor/ to your repository, for all dependencies are tracked with composer.lock anyway, and changing dependencies inside vendor (making them hardcoded) is against composer workflow.


As suggested by Kévin Dunglas, you can also try to look for the lost changes in the local history of your IDE (e.g. in PHPStorm).