且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何解决没有提交git存储冲突?

更新时间:2022-06-25 06:10:36

这种情况下,您将变更存储起来以便从原点拉出。可能是因为您的本地更改在某些设置文件中只是 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

完成。