13

我在我正在开发的 Rails 应用程序上遇到了这个问题。我正在开发一个功能分支,并想从最近的 master 中重新定位。我运行了以下命令:

$ git checkout master
$ git pull --rebase

如果我尝试结帐回我的功能分支,我会收到以下错误:

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

  modified:   Gemfile.lock

我尝试使用以下命令将 Gemfile.lock 解析回 aster,但均未成功:

$ git checkout -- Gemfile.lock
$ git stash
$ git reset HEAD --hard

每次我运行一个新的 git 命令时,我都会回到 Gemfile.lock ,其中的更改未暂存以进行提交。

以下是我正在使用的库的以下版本:

$ git --version => 2.3.3
$ bundler --version => 1.7.9
4

2 回答 2

33

There must be some process running in the background or some side-effect of executing the git commands in your shell that is modifying the Gemfile.lock.

I am not familiar with rvm's magic (although that sounds plausible); here are some other things to check:

  • In recent versions of Rails there is a "spring" background process that runs. Try running spring stop (or bin/spring stop or bundle exec spring stop) to gracefully terminate that process.
  • Likewise if you have any other Rails-related processes like rails server, guard, zeus, sidekiq, etc. running, try shutting those down.
  • You might be running a git pre-commit hook. Check the .git/hooks directory.
  • git might be an alias in your shell for another command. Run alias to see a list of shell aliases.
  • Your shell prompt might be executing code to do things like show the current git status and branch name in the prompt. This code would be executed after every shell command to redraw the prompt, and might have side-effects. Check your .bashrc or .bash_profile.
于 2015-03-18T23:43:15.137 回答
0

有时运行 rails 命令或其他 bundle exec 命令会默默地更新您的 Gemfile.lock。我猜你在你的 git 命令之间的某个时候这样做。或者你安装了一些奇怪的东西,它会无形地做到这一点。

(rvm 可以无形地做到这一点吗?我不知道。我认为 rvm 会做各种奇怪的事情并且不要使用它。)。

无论如何,发生这种情况的事实可能表明正在发生的其他事情不是您想要的——您确定您尝试一起提交的 Gemfile 和 Gemfile.lock 实际上是兼容的吗?通常,只要 Gemfile 发生变化,明智的做法是运行 bundle install 来获取新的 Gemfile.lock。如果您尝试提交实际上与 Gemfile 不兼容的 Gemfile.lock ...我不确定您为什么要这样做,通常我希望任何给定提交中的 Gemfile 和 Gemfile.lock兼容的。

要了解为什么某些东西(神秘的)可能会改变您的 Gemfile.lock,请在 Gemfile.lock 上执行 git diff 以查看它是如何改变的?

于 2015-03-18T22:03:29.823 回答