Rails的强大在其框架之中无处不体现。Gemfile.lock用来记录Application中的依赖Gem包,并详细记录了依赖Gem包的版本。当Application的环境发生变化时,我们可以用Bundle update来更新相关依赖包,也可以保持Gemfile.lock不变。

    当我们希望Application中的引用的包保持一致不变时,只要保持Gemfile.lock不变即可。这样,即使我们将Application迁移到另一个环境中时,也能保持代码及其功能的一致时。而我们开发C++或Java应用时,可没这么方便,特别是包的引用似乎不受控制。

    以下摘录Gemfile.lock的英文说明:

 
  
  1. THE GEMFILE.LOCK 
  2.  
  3. When you run bundle install, Bundler will persist the full names and versions of all gems that you used (including dependencies of the gems specified in the Gemfile(5)) into a file called Gemfile.lock. 
  4.  
  5. Bundler uses this file in all subsequent calls to bundle install, which guarantees that you always use the same exact code, even as your application moves across machines. 
  6.  
  7. Because of the way dependency resolution works, even a seemingly small change (for instance, an update to a point-release of a dependency of a gem in your Gemfile(5)) can result in radically different gems being needed to satisfy all dependencies. 
  8.  
  9. As a result, you SHOULD check your Gemfile.lock into version control. If you do not, every machine that checks out your repository (including your production server) will resolve all dependencies again, which will result in different versions of third-party code being used if any of the gems in the Gemfile(5) or any of their dependencies have been updated.