如何在 rails 中使用 git 管理 Gemfile.lock
How to manage Gemfile.lock with git in rails
我正在尝试删除我的 "Changes not staged for commit",而我的 Gemfile.lock 一直作为未暂存的文件重新出现。我相信这是因为我更新了捆绑器,因为更改是:
-
- BUNDLED WITH
- 1.10.5
首先,这些都不起作用,因为 Gemfile.lock 会自行更新:
git checkout -- Gemfile.lock
git stash save --keep-index --include-untracked
git stash drop
git reset HEAD
git clean -df
git checkout -- .
有效的是:
git update-index --assume-unchanged Gemfile.lock
看起来不错,运行宁 "git status":
On branch develop
Your branch is up-to-date with 'origin/develop'.
nothing to commit, working directory clean
我不能运行"git checkout origin/existing_branch"
error: Your local changes to the following files would be overwritten by checkout:
Gemfile.lock
Please, commit your changes or stash them before you can switch branches.
Gemfile.lock 的最佳做法是什么?如何在忽略远程的同时从远程拉取新分支?
不要将 Gemfile.lock
添加到您的 .gitignore
!
这破坏了锁定文件的意义。
您的 Rails 应用由 Gemfile
描述,它基于依赖项和软件版本使用对为您的应用安装的 gem 版本的松散描述。由于某些次要版本和依赖项升级可能会中断,因此锁定文件会使用特定版本描述您的应用程序,并 Git 引用特定提交,以便您可以在部署到 dev/testing/production 服务器 and/or 与您的同行共享 repo。
如果您确实忽略了锁定文件,任何新用户或服务器都将通过 Gemfile 安装 gems 到最新版本和依赖项,如 defined/limited。您将花费数小时试图弄清楚 "best mix of software that makes your app work locally" 锁定文件何时会为您完成。
更好的解决方案是停止使用 bundle update
,除非您希望更新 Gemfile
中的 gem。您应该几乎总是使用 bundle install
来处理锁定文件 - 它永远不会被更改。这在 b运行ches 和 git pulls 之间起作用。
但是,一旦您想为您的产品更新 gem 版本,您应该更新 Gemfile
、运行 bundle update <gemname>
,然后提交生成的 Gemfile
和 Gemfile.lock
最后,如果你不小心 运行 bundle update
而现在你有一个更新 Gemfile.lock
,你应该重置锁定文件并重新 运行 bundle install
我正在尝试删除我的 "Changes not staged for commit",而我的 Gemfile.lock 一直作为未暂存的文件重新出现。我相信这是因为我更新了捆绑器,因为更改是:
-
- BUNDLED WITH
- 1.10.5
首先,这些都不起作用,因为 Gemfile.lock 会自行更新:
git checkout -- Gemfile.lock
git stash save --keep-index --include-untracked
git stash drop
git reset HEAD
git clean -df
git checkout -- .
有效的是:
git update-index --assume-unchanged Gemfile.lock
看起来不错,运行宁 "git status":
On branch develop
Your branch is up-to-date with 'origin/develop'.
nothing to commit, working directory clean
我不能运行"git checkout origin/existing_branch"
error: Your local changes to the following files would be overwritten by checkout:
Gemfile.lock
Please, commit your changes or stash them before you can switch branches.
Gemfile.lock 的最佳做法是什么?如何在忽略远程的同时从远程拉取新分支?
不要将 Gemfile.lock
添加到您的 .gitignore
!
这破坏了锁定文件的意义。
您的 Rails 应用由 Gemfile
描述,它基于依赖项和软件版本使用对为您的应用安装的 gem 版本的松散描述。由于某些次要版本和依赖项升级可能会中断,因此锁定文件会使用特定版本描述您的应用程序,并 Git 引用特定提交,以便您可以在部署到 dev/testing/production 服务器 and/or 与您的同行共享 repo。
如果您确实忽略了锁定文件,任何新用户或服务器都将通过 Gemfile 安装 gems 到最新版本和依赖项,如 defined/limited。您将花费数小时试图弄清楚 "best mix of software that makes your app work locally" 锁定文件何时会为您完成。
更好的解决方案是停止使用 bundle update
,除非您希望更新 Gemfile
中的 gem。您应该几乎总是使用 bundle install
来处理锁定文件 - 它永远不会被更改。这在 b运行ches 和 git pulls 之间起作用。
但是,一旦您想为您的产品更新 gem 版本,您应该更新 Gemfile
、运行 bundle update <gemname>
,然后提交生成的 Gemfile
和 Gemfile.lock
最后,如果你不小心 运行 bundle update
而现在你有一个更新 Gemfile.lock
,你应该重置锁定文件并重新 运行 bundle install