Use patches使用补丁
Instead of committing your local changes, you can put them in a .patch file that you can apply to your sources later, send by email, and so on. 不必提交本地更改,您可以将它们放入.patch文件中,以便稍后应用于源、通过电子邮件发送等。Using patches is a convenient mechanism for sharing changes without checking them into to a VCS repository.使用补丁是一种方便的机制,用于共享更改,而无需将更改签入VCS存储库。
Create a patch from uncommited changes根据未限制的更改创建补丁
-
In the Local Changes view, select the file or the changelist based on which you want to create a patch, and choose Create Patch from Local Changes from the context menu.在“本地更改”视图中,选择要基于其创建修补程序的文件或更改列表,然后从上下文菜单中选择“从本地更改创建修补程序”。You can also select the changes for commit, click the arrow next to the Commit button and select Create Patch.也可以选择要提交的更改,单击提交按钮旁边的箭头,然后选择创建补丁。 -
In the dialog that opens, make sure that all changes you want to include in the patch are selected, enter a commit comment (optionally) and click Create Patch.在打开的对话框中,确保选择了要包含在修补程序中的所有更改,输入“提交注释”(可选)并单击创建补丁。 -
In the Patch File Settings dialog, modify the default patch file location if necessary, and click OK.在“补丁文件设置”对话框中,根据需要修改默认修补程序文件位置,然后单击“确定”。
If you do not need to save the patch to a file, and want, for example, to send it by email or through a messenger, you can right-click a file in the Local Changes view and choose Copy as Patch to Clipboard from the context menu.如果不需要将修补程序保存到文件中,并且希望(例如)通过电子邮件或messenger发送修补程序,则可以在“本地更改”视图中的文件上单击鼠标右键,然后从关联菜单中选择“将补丁复制到剪贴板”。
Create a patch from an entire commit从整个提交创建修补程序
-
Locate the commit that you want to create a patch from in the Log tab of the Version Control tool window Alt+9 and select Create Patch from the context menu.在“版本控制”工具窗口Alt+9的“日志”选项卡中找到要从中创建修补程序的提交,然后从关联菜单中选择“创建补丁”。 -
In the Patch File Settings dialog, modify the default patch file location if necessary, and click OK.在“补丁文件设置”对话框中,根据需要修改默认补丁文件位置,然后单击“确定”。
Create a patch from a file从文件创建补丁
-
Select the required file in any view (in the Project tool window, in the editor, in the Local Changes view, and so on).在任意图中(在项目工具窗口中,在编辑器中,在本局更改视图中等等)选择想要的文件。 -
Select Git | Show History from the main VCS menu or from the context menu of the selection. The History tab is added to the Git tool window showing the history for the selected file and allowing you to review and compare its revisions.
-
Right-click a revision and choose Create Patch from the context menu, or click the Create Patch icon
on the toolbar.
Apply patches应用补丁
-
Select VCS | Patch | Apply patch from the main menu.从主菜单中选择“版本控制”|“补丁”|“应用补丁”。 -
In the Apply Patch dialog that opens, specify the path to the .patch file you want to apply.
-
If necessary, click
and choose Map Base Directory to specify a directory relative to which file names in the patch file will be interpreted.
You can map a base directory to a single file, directory, or to a selection.您可以将基本目录映射到单个文件、目录或所选内容。 -
If the source code was edited after a patch was created, conflicts may arise.如果源代码是在创建修补程序后编辑的,则可能会发生冲突。To check if you patch can be applied without conflicts, click Show Diff若要检查修补程序是否可以在没有冲突的情况下应用,请单击“显示差异”Ctrl+D.
Ctrl+D。
If there are conflicts, the corresponding lines will be highlighted with red.如果存在冲突,则相应的行将以红色突出显示。 -
If you want to apply changes to files stored in different locations from those specified in the patch, you can strip off the leading directories by clicking
and choosing Remove All Leading Directories.
-
Select an existing changelist where you want to add the patch from the list, or specify the name of a new changelist in the Name field, and, optionally, enter a comment to this changelist.
-
If you want to make this changelist active, select the Set active option.
-
If you want WebStorm to preserve the context of a task associated with the new changelist on its deactivation and restore the context when the changelist becomes active, select the Track context option (see Tasks and contexts for details).
-
If you want to move the patch to a temporary storage (shelf) before applying it, click Import to shelf (see Shelve and unshelve changes for details). Otherwise, click OK.
You can also copy a patch file content and apply it by choosing VCS | Apply Patch from Clipboard from the main menu. This is convenient when you receive a patch by email, for example, and do not want to save it. For Git format patches, WebStorm extracts the commit message and the author and automatically fills the corresponding fields in the Commit tool window Alt+0.