git stash 错误 : git stash pop and ended up with merge conflicts

标签 git git-stash git-checkout

我做了一个 git stash pop 并以 merge 冲突告终。我从文件系统中删除了文件并执行了 git checkout 操作,如下所示,但它认为文件仍未 merge 。然后我尝试替换文件并再次执行 git checkout 并得到相同的结果。我尝试用 -f 标志强制它。任何帮助将不胜感激!

chirag-patels-macbook-pro:haloror patelc75$ git status
app/views/layouts/_choose_patient.html.erb: needs merge
app/views/layouts/_links.html.erb: needs merge
# On branch prod-temp
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       modified:   db/schema.rb
#
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       unmerged:   app/views/layouts/_choose_patient.html.erb
#       unmerged:   app/views/layouts/_links.html.erb

chirag-patels-macbook-pro:haloror patelc75$ git checkout app/views/layouts/_choose_patient.html.erb
error: path 'app/views/layouts/_choose_patient.html.erb' is unmerged
chirag-patels-macbook-pro:haloror patelc75$ git checkout -f app/views/layouts/_choose_patient.html.erb
warning: path 'app/views/layouts/_choose_patient.html.erb' is unmerged

最佳答案

参见 man git merge (如何解决冲突):

After seeing a conflict, you can do two things:

  • Decide not to merge. The only clean-ups you need are to reset the index file to the HEAD commit to reverse 2. and to clean up working tree changes made by 2. and 3.; git-reset --hard can be used for this.

  • Resolve the conflicts. Git will mark the conflicts in the working tree. Edit the files into shape and git add them to the index. Use git commit to seal the deal.

TRUE MERGE 下(查看 2. 和 3. 指的是什么):

When it is not obvious how to reconcile the changes, the following happens:

  1. The HEAD pointer stays the same.

  2. The MERGE_HEAD ref is set to point to the other branch head.

  3. Paths that merged cleanly are updated both in the index file and in your working tree.

  4. ...

所以:如果你想从你的工作树中删除存储更改,请使用 git reset --hard,如果你只想清理索引,请使用 git reset并将冲突留在您的工作树中以手动 merge 。

man git stash (OPTIONS, pop) 您还可以阅读:

Applying the state can fail with conflicts; in this case, it is not removed from the stash list. You need to resolve the conflicts by hand and call git stash drop manually afterwards.

关于git stash 错误 : git stash pop and ended up with merge conflicts,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2840816/

相关文章:

Git删除分支而不克隆?

git - 从 Google Cloud 克隆特定分支

Git 命令执行 pull 并将我的更改放在顶部而不 stash ?

git - 如何仅从给定提交中记录的文件中恢复几行?

git - 有没有办法将 "git checkout"和 *force* 参数解释为分支名称?

git - 将现有的 GitLab 项目移动到新的子组中

git - 当我已经有多个分支时应该如何添加新文件

git - 从 git repo 中只提取一个目录

git - git stash 的预期用例是什么?

git - 如何在 git stash/git stash pop 之后恢复索引?