git stash 错误:git stash pop 并最终导致合并冲突
我做了一个 git stash pop 并最终出现了合并冲突。我从文件系统中删除了这些文件,并执行了 git checkout ,如下所示,但它认为这些文件仍未合并。然后我尝试替换文件并再次执行 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
I did a git stash pop
and ended up with merge conflicts. I removed the files from the file system and did a git checkout
as shown below, but it thinks the files are still unmerged. I then tried replacing the files and doing a git checkout
again and same result. I event tried forcing it with -f
flag. Any help would be appreciated!
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
请参阅 man git merge (如何解决冲突):
在TRUE MERGE下(看看2.和3.指的是什么):
所以:如果您想从工作树中删除存储更改,请使用 git reset --hard ,或者如果您只想清理索引,请使用 git reset并将冲突留在工作树中以手动合并。
在 man git stash 下(选项,pop)您还可以阅读:
See man git merge (HOW TO RESOLVE CONFLICTS):
And under TRUE MERGE (to see what 2. and 3. refers to):
So: use
git reset --hard
if you want to remove the stash changes from your working tree, orgit reset
if you want to just clean up the index and leave the conflicts in your working tree to merge by hand.Under man git stash (OPTIONS, pop) you can read in addition:
我也发生过类似的事情。我还不想暂存这些文件,因此我使用 git add 添加了它们,然后执行了 git reset。这基本上只是添加然后取消了我的更改,但清除了未合并的路径。
I had a similar thing happen to me. I didn't want to stage the files just yet so I added them with
git add
and then just didgit reset
. This basically just added and then unstaged my changes but cleared the unmerged paths.如果像我一样,您通常想要的是用隐藏文件的内容覆盖工作目录的内容,并且您仍然遇到冲突,那么您想要的是使用 git checkout --theirs 解决冲突-- . 从根开始。
之后,您可以 git reset 将所有更改从索引带到工作目录,因为显然在发生冲突的情况下,对非冲突文件的更改保留在索引中。
您可能还想随后运行 git stash drop [] 来删除存储,因为 git stash pop 不会删除它,以防万一的冲突。
If, like me, what you usually want is to overwrite the contents of the working directory with that of the stashed files, and you still get a conflict, then what you want is to resolve the conflict using
git checkout --theirs -- .
from the root.After that, you can
git reset
to bring all the changes from the index to the working directory, since apparently in case of conflict the changes to non-conflicted files stay in the index.You may also want to run
git stash drop [<stash name>]
afterwards, to get rid of the stash, becausegit stash pop
doesn't delete it in case of conflicts.请注意,
Git 2.5(2015 年第 2 季度)未来的 Git 可能会尝试使这种情况变得不可能。请参阅 提交 ed178ef,作者:杰夫·金 (
peff
),2015 年 4 月 22 日。(由 Junio C Hamano 合并 --
gitster
-- 在 提交 05c3967,2015 年 5 月 19 日)注意:此内容已恢复。见下文。
问题
换句话说:
解决方案
请参阅提交 1937610(2015 年 6 月 15 日)和 提交 ed178ef(2015 年 4 月 22 日),作者:杰夫·金 (
peff
)。(由 Junio C Hamano --
gitster
-- 合并于 提交 bfb539b,2015 年 6 月 24 日)Note that
Git 2.5 (Q2 2015)a future Git might try to make that scenario impossible.See commit ed178ef by Jeff King (
peff
), 22 Apr 2015.(Merged by Junio C Hamano --
gitster
-- in commit 05c3967, 19 May 2015)Note: This has been reverted. See below.
Problem
In other words:
Solution
See commit 1937610 (15 Jun 2015), and commit ed178ef (22 Apr 2015) by Jeff King (
peff
).(Merged by Junio C Hamano --
gitster
-- in commit bfb539b, 24 Jun 2015)