Ruby-on-rails 拉是不可能的,因为你有未合并的文件,git stash 不起作用。不想承诺

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8044675/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 02:19:02  来源:igfitidea点击:

Pull is not possible because you have unmerged files, git stash doesn't work. Don't want to commit

ruby-on-railsgitgemgit-pullgit-stash

提问by JZ.

I just want to pull. I have changes to disregard, my Gemfile and Gemlock files and I'd be happy to just overwrite them and just pull. I tried stashing my changes away, this didn't work out for me. What do I do?

我只想拉。我有更改可以忽略,我的 Gemfile 和 Gemlock 文件,我很乐意覆盖它们并直接拉取。我尝试隐藏我的更改,这对我不起作用。我该怎么办?

git pull
M   Gemfile
U   Gemfile.lock
Pull is not possible because you have unmerged files.
Please, fix them up in the work tree, and then use 'git add/rm <file>'
as appropriate to mark resolution, or use 'git commit -a'.
~/projects/sms/apps2/apps2_admin(apps2)$ git stash save "saved"
Gemfile.lock: needs merge
Gemfile.lock: needs merge
Gemfile.lock: unmerged (4ea16799dba7bfe1db28adecf36dee1af5195c1a)
Gemfile.lock: unmerged (e77439c9f86d1d0eda7ae0787e3e158f90959e68)
Gemfile.lock: unmerged (d690d3860db1aa8e46c1bb2f4de3e52a297b5c26)
fatal: git-write-tree: error building trees
Cannot save the current index state
~/projects/sms/apps2/apps2_admin(apps2)$ git pull
M   Gemfile
U   Gemfile.lock
Pull is not possible because you have unmerged files.
Please, fix them up in the work tree, and then use 'git add/rm <file>'
as appropriate to mark resolution, or use 'git commit -a'.

回答by Ricardo Peres

git fetch origin
git reset --hard origin/master
git pull

Explanation:

解释:

  • Fetch will download everything from another repository, in this case, the one marked as "origin".
  • Reset will discard changes and revert to the mentioned branch, "master" in repository "origin".
  • Pull will just get everything from a remote repository and integrate.
  • Fetch 将从另一个存储库下载所有内容,在这种情况下,标记为“来源”的那个。
  • 重置将放弃更改并恢复到提到的分支,即存储库“原点”中的“主”。
  • Pull 只会从远程存储库中获取所有内容并进行集成。

See documentation at http://git-scm.com/docs.

请参阅http://git-scm.com/docs 上的文档。

回答by Amber

You can use git checkout <file>to check out the committed version of the file (thus discarding your changes), or git reset --hard HEADto throw away any uncommitted changes for all files.

您可以使用git checkout <file>检出文件的已提交版本(从而放弃您的更改),或丢弃git reset --hard HEAD所有文件的任何未提交的更改。

回答by max

I've tried both these and still get failure due to conflicts. At the end of my patience, I cloned master in another location, copied everything into the other branch and committed it. which let me continue. The "-X theirs" option should have done this for me, but it did not.

我已经尝试了这两种方法,但由于冲突仍然失败。在我的耐心结束时,我将 master 克隆到另一个位置,将所有内容复制到另一个分支并提交。让我继续。“-X theirs”选项应该为我完成此操作,但它没有。

git merge -s recursive -X theirs master

error: 'merge' is not possible because you have unmerged files. hint: Fix them up in the work tree, hint: and then use 'git add/rm ' as hint: appropriate to mark resolution and make a commit, hint: or use 'git commit -a'. fatal: Exiting because of an unresolved conflict.

git merge -s recursive -X 他们的主人

错误:“合并”是不可能的,因为您有未合并的文件。提示:在工作树中修复它们,提示:然后使用“git add/rm”作为提示:适合标记分辨率并进行提交,提示:或使用“git commit -a”。致命:由于未解决的冲突而退出。

回答by chacham15

I've had the same error and I solve it with: git merge -s recursive -X theirs origin/master

我遇到了同样的错误,我用以下方法解决了它:git merge -s recursive -X theirs origin/master