Instead of committing your changes, you can put them in a
.patch file that you can apply to your sources later, or send by email, etc.
Create a patch
To create a patch based on uncommitted changes, do the following:
- Open the Version Control tool window (Alt+9) and switch to the Local Changes tab.
- Select a file or a changelist based on which you want to create a patch.
- Select Create Patch from the context menu or from the main VCS menu.
- 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 a patch to a file, and want, for example, to send it by email or through a messenger, you can select Copy as Patch to Clipboard from the context menu of the selected file or changelist, and then paste it to a message body.
You can also create a patch based on changes that have already been committed. To create a patch from an entire commit, locate it in the Log view, and select Create Patch from the context menu. If you need to create a patch on a single file, and the corresponding commit contains multiple files, do the following:
- Select the required file in any view (in the Project tool window, in the editor, in the Local Changes tab of the Version Control tool window, etc.).
- Select Git | Show History from the main VCS menu or from the context menu of the selection. The History tab is added to the Version Control tool window.
- Right-click a revision and choose Create Patch from the context menu, or click the Create Patch icon on the toolbar.
Apply a patch
To apply changes stored in a file to your sources, do the following:
- Select VCS | 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 the Map base directory icon 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 the Show Diff icon or press Ctrl+D. If there are conflicts, the corresponding lines will be highlighted in 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 using the Strip Directory button .
- Select an existing changelist where you want to add the patch from the drop-down 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 PhpStorm 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 Managing tasks and contexts for details).
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, PhpStorm extracts the commit message and the author and automatically fills the corresponding fields in the Commit Changes dialog.