douan2907
douan2907
2013-10-26 20:07

如何强制composer重新安装库?

已采纳

I'm using the ZF2 skeleton app and it has a .gitignore that prevents external libraries from being commited to git. While debugging I like to go and change stuff here and there in the libraries' source to learn how things work. If these were version controlled it would be very easy to revert them back to their original state.

How can I force Composer to reinstall a particular framework so that I can get a fresh -unmodified- copy again?

PS: Please don't suggest removing the .gitignore file since it's there for a reason; it prevents my third party libraries from getting into my app's repository. I can always install them during an automated deployment.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

6条回答

  • dptsivmg82908 dptsivmg82908 8年前

    You can use the --prefer-source flag for composer to checkout external packages with the VCS information (if any available). You can simply revert to the original state. Also if you issue the composer update command composer will detect any changes you made locally and ask if you want to discard them.

    Your .gitignore file is related to your root project (ZF2 skeleton) and it prevents the vendor dir (where your third party libs are) from committing to your own VCS. The ignore file is unrelated to the git repo's of your vendors.

    点赞 评论 复制链接分享
  • douya1938 douya1938 4年前

    I didn't want to delete all the packages in vendor/ directory, so here is how I did it:

    1. rm -rf vendor/package-i-messed-up
    2. composer install again
    点赞 评论 复制链接分享
  • douju6542 douju6542 2年前

    Reinstall the dependencies. Remove the vendor folder (manually) or via rm command (if you are in the project folder, sure) on Linux before:

    rm -rf vendor/
    
    composer update -v
    

    https://www.dev-metal.com/composer-problems-try-full-reset/

    点赞 评论 复制链接分享
  • dounuo7954 dounuo7954 6年前

    Just clear your vendors folder

    rm -rf vendor/*
    
    点赞 评论 复制链接分享
  • doujiexin1136 doujiexin1136 5年前

    What I did:

    1. Deleted that particular library's folder
    2. composer update --prefer-source vendor/library-name

    It fetches the library again along with it's git repo

    点赞 评论 复制链接分享
  • donglie9067 donglie9067 2年前

    As user @aaracrr pointed out in a comment on another answer probably the best answer is to re-require the package with the same version constraint.

    ie.

    composer require vendor/package
    

    or specifying a version constraint

    composer require vendor/package:^1.0.0
    
    点赞 评论 复制链接分享

相关推荐