如何解决没有提交git存储冲突? [英] How to resolve git stash conflict without commit?

查看:129
本文介绍了如何解决没有提交git存储冲突?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于在此问题中提出,我也想知道如何解决冲突的 git隐藏弹出窗口而不添加对提交的所有修改(就像git stash pop没有冲突一样)。

As asked in this question, I also want to know how to resolve a conflicting git stash pop without adding all modifications to a commit (just like "git stash pop" without a conflict does).

我目前的方法非常不酷,因为我这样做:

My current approach is very uncool because I do it this way:

git stash pop -> CONFLICT
git stash drop
[resolve conflict]
[add conflict files]
git reset HEAD <all files that are in commit-mode>

[更新]一种重现它的方法:

[Update] A way to reproduce it:

mkdir foo; cd foo; git init
echo "1" > one
echo "2" > two
git add -A; git commit -m "first"
echo "1.1" > one
echo "2.1" > two
git stash
echo "2.2" > two
git commit -a -m "second"
echo "Only this file would stay in HEAD without the conflict" > third
git add third
git stash pop
git status

2016-06-27:在示例中添加了一个名为'third'的新文件,用于显示像scy这样的解决方案的解决方法仅适用于空HEAD,但不修复HEAD没有类似内容的初始问题对于 git stash pop 没有冲突。

2016-06-27: Added a new file called 'third' to the example to show that workarounds like the solution from scy only work for empty HEADs but don't fix the initial problem that the HEAD doesn't have the same content like for a git stash pop without a conflict.

推荐答案

这种情况下,您将变更存储起来以便从原点拉出。可能是因为您的本地更改在某些设置文件中只是 debug:true

Suppose you have this scenario where you stash your changes in order to pull from origin. Possibly because your local changes are just debug: true in some settings file. Now you pull and someone has introduced a new setting there, creating a conflict.

git status 说:

# On branch master
# Unmerged paths:
#   (use "git reset HEAD <file>..." to unstage)
#   (use "git add/rm <file>..." as appropriate to mark resolution)
#
#   both modified:      src/js/globals.tpl.js
no changes added to commit (use "git add" and/or "git commit -a")

好的。我决定采用Git的建议:我解决了冲突并承诺:

Okay. I decided to go with what Git suggested: I resolved the conflict and committed:

vim src/js/globals.tpl.js
# type type type …
git commit -a -m WIP   # (short for "work in progress")

现在我的工作副本处于我想要的状态,但是我创建了一个我不想拥有的提交。如何在不修改工作副本的情况下摆脱该提交?等等,这里有一个很受欢迎的命令!

Now my working copy is in the state I want, but I have created a commit that I don't want to have. How do I get rid of that commit without modifying my working copy? Wait, there's a popular command for that!

git reset HEAD^

我的工作副本并未更改,但WIP提交已消失。这正是我想要的! (请注意,我在这里并没有使用 - soft ,因为如果存储器中存在自动合并的文件,它们将自动启动,因此您最终会这些文件在 reset 之后再次执行。)

My working copy has not been changed, but the WIP commit is gone. That's exactly what I wanted! (Note that I'm not using --soft here, because if there are auto-merged files in your stash, they are auto-staged and thus you'd end up with these files being staged again after reset.)

但还剩下一件事情: code> git stash pop 提醒我们应用状态可能会因冲突而失败;在这种情况下,它不会从存储列表中删除。然后手动调用 git stash drop 这就是我们现在所做的:

But there's one more thing left: The man page for git stash pop reminds us that "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." So that's exactly what we do now:

git stash drop

完成。

这篇关于如何解决没有提交git存储冲突?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆