如何解决“git stash apply”引起的“删除/修改”冲突

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10056165/
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-19 06:43:39  来源:igfitidea点击:

How to resolve "delete/modify" conflict caused by "git stash apply"

git

提问by stupakov

I recently did a git stash, then did some work on the branch and committed it, and got these errors when trying to do a git stash apply:

我最近做了一个git stash,然后在分支上做了一些工作并提交了它,并在尝试做一个时遇到了这些错误git stash apply

CONFLICT (delete/modify): app/controllers/orders_controller.rb deleted in Updated upstream and modified in Stashed changes. Version Stashed changes of app/controllers/orders_controller.rb left in tree.
CONFLICT (content): Merge conflict in app/models/product.rb

git statusshows the following:

git status显示以下内容:

 $ git status
# On branch develop
# Your branch is ahead of 'origin/develop' by 16 commits.
# Unmerged paths: 
#   (use "git reset HEAD <file>..." to unstage)
#   (use "git add/rm <file>..." as appropriate to mark resolution)
#
#   deleted by us:      app/controllers/orders_controller.rb
#   both modified:      app/models/product.rb

The file marked "delete/modify" was a new file that I added and hadn't yet committed before the stash.
I'd like to be back in the state I was in before the git stash-- having uncommitted local changes. Can you suggest how to make that happen?

标记为“删除/修改”的文件是我添加的一个新文件,但在stash.
我想回到我之前的状态git stash——没有提交本地更改。你能建议如何做到这一点吗?

Thanks.

谢谢。

采纳答案by GoZoner

You are popping the stash onto a different state; state that has one additional commit. And worse, the commit has introduced merge conflicts, as you know.

您正在将藏匿处弹出到不同的状态;有一次额外提交的状态。更糟糕的是,如您所知,提交引入了合并冲突。

You have two options:

您有两个选择:

  1. pop that stash onto the latest commit and resolve the conflicts
  2. pop the stash onto the prior commit.
  1. 将存储弹出到最新提交并解决冲突
  2. 将 stash 弹出到先前的提交中。

Sounds like #2 is what you want to do. Use:

听起来#2 就是你想要做的。用:

    git stash branch new_branch [<stash>]  # <stash> will be the last one if not provided.

回答by raj240

This worked for me.

这对我有用。

Do a-

做一个-

git mergetool

Then you would be asked to pick the modified or deleted file or abort, and after this do one more time-

然后你会被要求选择修改或删除的文件或中止,然后再做一次 -

git mergetool

This would resolve the merge conflict and you can stash pop your changes.

这将解决合并冲突,您可以隐藏您的更改。

回答by mrgloom

In my case git add <file>helped:

在我的情况下git add <file>帮助:

Here is example https://gist.github.com/SgtPooki/10efd02b066a8704b776

这是示例https://gist.github.com/SgtPooki/10efd02b066a8704b776

回答by Kit Ho

You need to resolve the conflict! Since you have updated the latest repository, the two files has been changed, project.rb and orders_controller.rb has been modified in the latest repository. At the same time, your local change (stash) has also modified these two file, when you apply them, there will be conflict.

您需要解决冲突!由于你更新了最新的仓库,所以修改了两个文件,project.rb和orders_controller.rb在最新的仓库中被修改了。同时,你的本地更改(stash)也修改了这两个文件,当你应用它们时,就会发生冲突。

You need to solve the conflict in order to apply your local change.

您需要解决冲突才能应用您的本地更改。

For the first file, orders_controller.rb the latest repo is deleted, do you want to keep it or not when you push your later commit?

对于第一个文件,orders_controller.rb 最新的 repo 被删除,当你推送你以后的提交时,你想保留它吗?

For the second file, project.rb you need to resolve the conflict in the file.

对于第二个文件 project.rb,您需要解决文件中的冲突。