Gemfile.lock始终具有未提交的更改

时间:2022-01-22 00:21:36

I am running into this problem on a rails app I am working on. I was working on a feature branch and wanted to rebase from the most recent master. I ran the following commands:

我正在努力的rails应用程序上遇到这个问题。我正在开发一个功能分支,并希望从最新的主人那里重新定义。我运行了以下命令:

$ git checkout master
$ git pull --rebase

If I try to checkout back to my feature branch I get the following error:

如果我尝试检出我的功能分支,我会收到以下错误:

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

I have tried the following commands to resolve the Gemfile.lock back to aster with none of them being successful:

我尝试了以下命令将Gemfile.lock解析回aster,但没有一个成功:

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

Every time I run a new git command I go back to the Gemfile.lock having changes not staged for commit.

每次我运行一个新的git命令时,我都会回到Gemfile.lock,这些更改没有为commit提交。

Here are the following versions of libraries I am working with:

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

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

2 个解决方案

#1


27  

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.

必须在后台运行某个进程或在shell中执行git命令的一些副作用正在修改Gemfile.lock。

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

我不熟悉rvm的魔法(虽然听起来似乎有道理);这里有一些其他要检查的事情:

  • 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.
  • 在最新版本的Rails中,有一个“spring”后台进程运行。尝试运行弹簧停止(或箱/弹簧停止或捆绑执行弹簧停止)以正常终止该过程。
  • Likewise if you have any other Rails-related processes like rails server, guard, zeus, sidekiq, etc. running, try shutting those down.
  • 同样,如果你有任何其他与Rails相关的进程,如rails server,guard,zeus,sidekiq等运行,请尝试关闭它们。
  • You might be running a git pre-commit hook. Check the .git/hooks directory.
  • 您可能正在运行git pre-commit钩子。检查.git / hooks目录。
  • git might be an alias in your shell for another command. Run alias to see a list of shell aliases.
  • git可能是shell中别名的另一个命令。运行别名以查看shell别名列表。
  • 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.
  • 您的shell提示符可能正在执行代码以执行诸如在提示中显示当前git状态和分支名称之类的操作。此代码将在每个shell命令之后执行以重绘提示,并且可能具有副作用。检查.bashrc或.bash_profile。

#2


0  

There are times that running a rails command or other bundle exec command will silently update your Gemfile.lock. I am guessing you are doing that sometime in between your git commands. Or you have something weird installed that does that invisibly.

有时运行rails命令或其他bundle exec命令会以静默方式更新您的Gemfile.lock。我猜你在你的git命令之间的某个时间做这件事。或者你有一些奇怪的安装,这是无形的。

(Could rvm do this invisibly? I don't know. I think rvm does all kinds of odd stuff and don't use it.).

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

At any rate, the fact that this is happening is probably evidence of something else going on that isn't what you want -- are you sure the Gemfile and Gemfile.lock you are trying to commit together are actually compatible? Normally any time a Gemfile changes at all, it is wise to run bundle install to get a new Gemfile.lock. If you are trying to commit a Gemfile.lock which actually isn't compatible with the Gemfile... I am not sure why you would want to do that anyway, normally I want the Gemfile and Gemfile.lock in any given commit to be compatible.

无论如何,发生这种情况的事实可能是其他事情的证据,这不是你想要的 - 你确定你试图提交的Gemfile和Gemfile.lock实际上是兼容的吗?通常,只要Gemfile发生任何变化,运行bundle install就可以获得新的Gemfile.lock。如果你试图提交一个实际上与Gemfile不兼容的Gemfile.lock ...我不知道你为什么要这样做,通常我希望在任何给定的提交中都有Gemfile和Gemfile.lock兼容。

To get a clue as to why something (mysterious) may be changing your Gemfile.lock, do a git diff on the Gemfile.lock to see how it's changed?

为了弄清楚为什么某些东西(神秘的)可能会改变你的Gemfile.lock,在Gemfile.lock上做一个git diff来看看它是如何改变的?

#1


27  

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.

必须在后台运行某个进程或在shell中执行git命令的一些副作用正在修改Gemfile.lock。

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

我不熟悉rvm的魔法(虽然听起来似乎有道理);这里有一些其他要检查的事情:

  • 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.
  • 在最新版本的Rails中,有一个“spring”后台进程运行。尝试运行弹簧停止(或箱/弹簧停止或捆绑执行弹簧停止)以正常终止该过程。
  • Likewise if you have any other Rails-related processes like rails server, guard, zeus, sidekiq, etc. running, try shutting those down.
  • 同样,如果你有任何其他与Rails相关的进程,如rails server,guard,zeus,sidekiq等运行,请尝试关闭它们。
  • You might be running a git pre-commit hook. Check the .git/hooks directory.
  • 您可能正在运行git pre-commit钩子。检查.git / hooks目录。
  • git might be an alias in your shell for another command. Run alias to see a list of shell aliases.
  • git可能是shell中别名的另一个命令。运行别名以查看shell别名列表。
  • 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.
  • 您的shell提示符可能正在执行代码以执行诸如在提示中显示当前git状态和分支名称之类的操作。此代码将在每个shell命令之后执行以重绘提示,并且可能具有副作用。检查.bashrc或.bash_profile。

#2


0  

There are times that running a rails command or other bundle exec command will silently update your Gemfile.lock. I am guessing you are doing that sometime in between your git commands. Or you have something weird installed that does that invisibly.

有时运行rails命令或其他bundle exec命令会以静默方式更新您的Gemfile.lock。我猜你在你的git命令之间的某个时间做这件事。或者你有一些奇怪的安装,这是无形的。

(Could rvm do this invisibly? I don't know. I think rvm does all kinds of odd stuff and don't use it.).

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

At any rate, the fact that this is happening is probably evidence of something else going on that isn't what you want -- are you sure the Gemfile and Gemfile.lock you are trying to commit together are actually compatible? Normally any time a Gemfile changes at all, it is wise to run bundle install to get a new Gemfile.lock. If you are trying to commit a Gemfile.lock which actually isn't compatible with the Gemfile... I am not sure why you would want to do that anyway, normally I want the Gemfile and Gemfile.lock in any given commit to be compatible.

无论如何,发生这种情况的事实可能是其他事情的证据,这不是你想要的 - 你确定你试图提交的Gemfile和Gemfile.lock实际上是兼容的吗?通常,只要Gemfile发生任何变化,运行bundle install就可以获得新的Gemfile.lock。如果你试图提交一个实际上与Gemfile不兼容的Gemfile.lock ...我不知道你为什么要这样做,通常我希望在任何给定的提交中都有Gemfile和Gemfile.lock兼容。

To get a clue as to why something (mysterious) may be changing your Gemfile.lock, do a git diff on the Gemfile.lock to see how it's changed?

为了弄清楚为什么某些东西(神秘的)可能会改变你的Gemfile.lock,在Gemfile.lock上做一个git diff来看看它是如何改变的?