我做了一个 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:
The HEAD pointer stays the same.
The MERGE_HEAD ref is set to point to the other branch head.
Paths that merged cleanly are updated both in the index file and in your working tree.
...
所以:如果你想从你的工作树中删除存储更改,请使用 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/