Visual Studio Code 如何解决与 git 的合并冲突?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38216541/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Visual Studio Code how to resolve merge conflicts with git?
提问by annedroiid
I tried to merge my branch with another branch and there was a merge conflict. In Visual Studio Code (version 1.2.1) I resolved all of the issues, however when I try to commit it keeps giving me this message:
我试图将我的分支与另一个分支合并,但发生了合并冲突。在 Visual Studio Code(1.2.1 版)中,我解决了所有问题,但是当我尝试提交时,它不断给我这条消息:
You should first resolve the un-merged changes before committing your changes.
在提交更改之前,您应该首先解决未合并的更改。
I've tried googling it but I can't find out why it won't let me commit my changes, all of the conflicts have disappeared.
我试过用谷歌搜索它,但我不知道为什么它不会让我提交我的更改,所有的冲突都消失了。
采纳答案by annedroiid
After trial and error I discovered that you need to stage the file that had the merge conflict, then you can commit the merge.
经过反复试验,我发现您需要暂存具有合并冲突的文件,然后您可以提交合并。
回答by Sajeetharan
With VSCode you can find the merge conflicts easily with the following UI.
使用 VSCode,您可以使用以下 UI 轻松找到合并冲突。
(if you do not have the topbar, set "editor.codeLens": true
in User Preferences)
(如果您没有顶栏,请"editor.codeLens": true
在用户首选项中设置)
It indicates the current change that you have and incoming change from the server. This makes it easy to resolve the conflicts - just press the buttons above <<<< HEAD
.
它表示您拥有的当前更改以及来自服务器的传入更改。这使得解决冲突变得容易——只需按上面的按钮<<<< HEAD
。
If you have multiple changes and want to apply all of them at once - open command palette (View -> Command Palette) and start typing merge - multiple options will appear including Merge Conflict: Accept Incoming
, etc.
如果您有多项更改并希望一次应用所有更改 - 打开命令面板(查看 -> 命令面板)并开始输入合并 - 将出现多个选项,包括Merge Conflict: Accept Incoming
等。
回答by B12Toaster
For those who are having a hard time finding the "merge buttons".
对于那些很难找到“合并按钮”的人。
The little lightbulp icon with merge options only shows up if you click precisely on the "merge conflict marker"
带有合并选项的小灯泡图标仅在您精确单击“合并冲突标记”时才会显示
<<<<<<<
Steps (in VS Code 1.29.x):
步骤(在 VS Code 1.29.x 中):
回答by Geoffrey Hale
回答by Tim Biegeleisen
The error message you are getting is a result of Git still thinking that you have not resolved the merge conflicts. In fact, you already have, but you need to tell Git that you have done this by addingthe resolved files to the index.
您收到的错误消息是 Git 仍然认为您尚未解决合并冲突的结果。实际上,您已经有了,但是您需要通过将解析的文件添加到索引来告诉 Git 您已经完成了此操作。
This has the side effect that you could actually just add the files withoutresolving the conflicts, and Git would still think that you have. So you should be diligent in making sure that you have really resolved the conflicts. You could even run the build and test the code before you commit.
这具有副作用,您实际上可以只添加文件而不解决冲突,Git 仍然会认为您已经解决了。所以你应该努力确保你真的解决了冲突。您甚至可以在提交之前运行构建并测试代码。
回答by Qiang Li
For VS Code 1.38 or if you could not find any "lightbulb" button. Pay close attention to the greyed out text above the conflicts; there is a list of actions you can take.
对于 VS Code 1.38 或者如果您找不到任何“灯泡”按钮。密切注意冲突上方的灰色文本;有一个您可以采取的行动列表。