Resolve conflicts解决冲突
Depending on your version control system, conflicts may arise in different situations.根据版本控制系统的不同,在不同的情况下可能会出现冲突。
When you work in a team, you may come across a situation when somebody commits changes to a file you are currently working on. 当您在团队中工作时,您可能会遇到这样的情况:有人对您当前正在处理的文件提交更改。If these changes do not overlap (that is, changes were made to different lines of code), the conflicting files are merged automatically. 如果这些更改不重叠(即对不同的代码行进行了更改),则会自动合并冲突的文件。However, if the same lines were affected, your version control system cannot randomly pick one side over the other, and asks you to resolve the conflict.但是,如果同一行受到影响,则版本控制系统无法随机选择一边而不是另一边,并要求您解决冲突。
Conflicts may also arise when merging, rebasing or cherry-picking branches.合并、重定基址或挑选分支时也可能发生冲突。
Non-Distributed Version Control Systems非分布式版本控制系统
When you try to edit a file that has a newer version on the server, WebStorm informs you about that, showing a message popup in the editor:当您尝试编辑服务器上具有较新版本的文件时,WebStorm会通知您,并在编辑器中显示一条弹出消息:
In this case, you should update your local version before changing the file, or merge changes later.在这种情况下,您应该在更改文件之前更新本地版本,或者稍后合并更改。
If you attempt to commit a file that has a newer repository version, the commit fails, and an error is displayed in the bottom right corner telling you that the file you are trying to commit is out of date.如果尝试提交具有较新存储库版本的文件,提交将失败,并且右下角将显示一个错误,告诉您尝试提交的文件已过期。
If you synchronize a file that already has local changes with a newer repository version committed by somebody else, a conflict occurs. 如果将已进行本地更改的文件与其他人提交的较新存储库版本同步,则会发生冲突。The conflicting file gets the Merged with conflicts status. 冲突文件获取“合并但存在冲突”状态。The file remains in the same changelist in the Local Changes view, but its name is highlighted in red. 该文件保留在本地更改视图中的相同更改列表中,但其名称以红色突出显示。If the file is currently opened in the editor, the filename on the tab header is also highlighted in red.如果文件当前在编辑器中打开,则选项卡标题上的文件名也会以红色突出显示。
Distributed Version Control Systems分布式版本控制系统
Under distributed version control systems, such as Git and Mercurial, conflicts arise when a file you have committed locally has changes to the same lines of code as the latest upstream version and when you attempt to perform one of the following operations: pull, merge, rebase, cherry-pick, unstash, or apply patch.在分布式版本控制系统(如Git和Mercurial)下,当您在本地提交的文件与最新的上游版本的代码行发生更改时,以及当您尝试执行以下操作之一时,就会出现冲突:拉取、合并、重基、切利拾取、取消粘贴或应用修补程序。
If there are conflicts, these operations will fail and you will be prompted to accept the upstream version, prefer your version, or merge the changes manually:如果存在冲突,这些操作将失败,系统将提示您接受上游版本、首选您的版本或手动合并更改:

The Conflicts dialog is triggered automatically when a conflict is detected on the Version Control level.在版本控制级别上检测到冲突时,将自动触发“冲突”对话框。
If you click Close in this dialog, or call a Git operation that leads to a merge conflict from command line, a Merge Conflicts node will appear in the Local Changes view with a link to resolve them:如果在此对话框中单击“关闭”,或从命令行调用导致合并冲突的Git操作,则“本地更改”视图中将显示一个“合并冲突”节点,其中包含解决这些冲突的链接:

WebStorm provides a tool for resolving conflicts locally. WebStorm提供了一个本地解决冲突的工具。This tool consists of three panes:此工具由三个窗格组成:
-
The left page shows the read-only local copy左侧页面显示只读本地副本 -
The right pane shows the read-only version checked in to the repository右侧窗格显示签入存储库的只读版本 -
The central pane shows a fully-functional editor where the results of merging and conflict resolving are displayed.中央窗格显示一个功能齐全的编辑器,其中显示合并和冲突解决的结果。Initially, the contents of this pane is the same as the base revision of the file, that is, the revision from which both conflicting versions are derived.最初,此窗格的内容与文件的基本版本相同,即从中派生两个冲突版本的版本。

Resolve conflicts解决冲突
-
Click Merge in the Conflicts dialog, the Resolve link in the Local Changes view, or select the conflicting file in the editor and choose VCS | <your_VCS> | Resolve Conflicts from the main menu.在“冲突”对话框中单击“本地更改”视图中的“解决”链接“合并”,或在编辑器中选择冲突文件并从主菜单中选择“VCS”|<your_VCS>|“解决冲突”。 -
To automatically merge all non-conflicting changes, click要自动合并所有非冲突更改,请单击工具栏上的(Apply All Non-Conflicting Changes) on the toolbar.
(应用所有非冲突更改)。
You can also use the还可以使用(Apply Non-Conflicting Changes from the Left Side) and
(Apply Non-Conflicting Changes from the Right Side) to merge non-conflicting changes from the left/right parts of the dialog respectively.
(从左侧应用非冲突更改)和
(从右侧应用非冲突更改)分别合并对话框左/右部分的非冲突更改。
-
To resolve a conflict, you need to select which action to apply (accept要解决冲突,您需要选择要对左侧(本地)和右侧(存储库)版本应用(接受or ignore
) to the left (local) and the right (repository) version, and check the resulting code in the central pane:
或忽略
)的操作,并在中心窗格中检查生成的代码:
You can also right-click a highlighted conflict in the central pane and use the commands from the context menu.您还可以右键单击中心窗格中突出显示的冲突,并使用关联菜单中的命令。The Resolve using Left and Resolve using Right commands provide a shortcut to accepting changes from one side and ignoring them from the other side respectively:“使用左键解析”和“使用右键解析”命令分别提供了从一侧接受更改和从另一侧忽略更改的快捷方式:For simple conflicts (for example, if an extra line has been added in one of the revisions), the Resolve simple conflicts对于简单冲突(例如,如果在其中一个修订中添加了额外的行),工具栏上会显示“解决简单冲突”button that allows merging the changes in one click becomes available on the toolbar.
按钮,该按钮允许在一次单击中合并更改。
Such conflicts are not resolved with the Apply All Non-Conflicting Changes action since you must make sure that they are resolved properly.“应用所有非冲突更改”操作不会解决此类冲突,因为您必须确保这些冲突得到正确解决。 -
It may also be useful to compare different versions to resolve a conflict.比较不同版本以解决冲突也可能很有用。Use the使用toolbar button to invoke the list of options.
工具栏按钮调用选项列表。
Note that Base refers to the file version that the local and the repository versions originated from (initially displayed in the middle pane), while Middle refers to the resulting version.注意,“基础”指的是本地版本和存储库版本的文件版本(最初显示在中间窗格中),而“中间”则是生成的版本。 -
Review merge results in the central pane and click Apply.在中心窗格中查看合并结果,然后单击“应用”。
Productivity tips生产力提示
Apply non-conflicting changes automatically自动应用无冲突的更改-
You can configure WebStorm to always apply non-conflicting changes automatically instead of telling it to do so from the Merge dialog.您可以将WebStorm配置为始终自动应用无冲突的更改,而不是从“合并”对话框中告诉它这样做。To do this, select the Automatically apply non-conflicting changes option on the Tools | Diff Merge page of the IDE settings Ctrl+Alt+S.为此,请在IDE设置Ctrl+Alt+S的“工具”|“差异合并”页面上选择“自动应用非冲突更改”选项。 Manage changes in the central pane管理更改在中心窗格中。-
You can manage changes in the central pane using the toolbar that appears when you hover the mouse cursor over a change marker in the gutter, and then click it.可以使用将鼠标光标悬停在檐槽中的更改标记上,然后单击该标记时显示的工具栏来管理中心窗格中的更改。The toolbar is displayed together with a frame showing the previous contents of the modified line:工具栏将与显示修改行以前内容的框架一起显示:For example, when there are multiple non-conflicting changes, and you only need to skip one or two of them, it's easier to apply all of them simultaneously using the Apply all non-conflicting changes action, and then undo the unwanted ones using the Revert action from this toolbar.例如,如果存在多个非冲突更改,并且您只需要跳过其中一个或两个,则可以使用“应用所有非冲突更改”操作同时应用所有更改,然后使用此工具栏中的“还原”操作撤消不需要的更改。