# 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. Using patches is a convenient mechanism for sharing changes without checking them in a Git repository.

Procedure: Create a patch from uncommitted changes

1. In the  Commit tool window (`Alt+0` (Windows), `⌘ 0` (macOS), `⌘ 0` (IntelliJ IDEA Classic (macOS)), `⌘ 0` (macOS System Shortcuts), `Alt+0` (XWin), `Alt+0` (GNOME), `Alt+0` (KDE), `Alt+0` (Emacs), `Alt+0` (Sublime Text), `⌘ 0` (Sublime Text (macOS)), `Alt+0` (NetBeans), `Alt+0` (Visual Studio), `Alt+0` (Visual Studio (macOS)), `Alt+0` (Eclipse), `⌘ 0` (Eclipse (macOS)) ) , select the file or changelist that you want to include in the patch, and choose Create Patch from Local Changes from the context menu.

2. In the dialog that opens, make sure that all the changes you want to include in the patch are selected, enter a commit comment (it will be used as the patch file name), and click Create Patch.

3. In the Patch File Settings dialog, specify the following details:

* The patch file location: choose the default location or select the To clipboard option if you do not want to save the patch to a file.

* Base path: specify the path relative to which paths inside the patch file will be written. Normally, this is your project directory, but you may want to use a relative path, for example, if the modified files are stored inside your Git repository.

* Reverse patch: select this option if you want to create a patch that reverts the changes you have made.

* Encoding: select the encoding for the patch file from the drop-down list.

If you do not need to save the patch to a file (for example, you want to send it by email instead), right-click the necessary file(s) in the  Commit tool window (`Alt+0` (Windows), `⌘ 0` (macOS), `⌘ 0` (IntelliJ IDEA Classic (macOS)), `⌘ 0` (macOS System Shortcuts), `Alt+0` (XWin), `Alt+0` (GNOME), `Alt+0` (KDE), `Alt+0` (Emacs), `Alt+0` (Sublime Text), `⌘ 0` (Sublime Text (macOS)), `Alt+0` (NetBeans), `Alt+0` (Visual Studio), `Alt+0` (Visual Studio (macOS)), `Alt+0` (Eclipse), `⌘ 0` (Eclipse (macOS)) )  and choose Copy as Patch to Clipboard from the context menu.

Procedure: Create a patch from an entire commit

1. In the  Log tab of the   Git tool window  `Alt+9` (Windows), `⌘ 9` (macOS), `⌘ 9` (IntelliJ IDEA Classic (macOS)), `⌘ 9` (macOS System Shortcuts), `Alt+9` (XWin), `Alt+9` (GNOME), `Alt+9` (KDE), `Alt+9` (Emacs), `Alt+9` (Sublime Text), `⌘ 9` (Sublime Text (macOS)), `Alt+9` (NetBeans), `Alt+9` (Visual Studio), `⌘ 9` (Visual Studio (macOS)), `Alt+9` (Eclipse), `⌘ 9` (Eclipse (macOS))  , locate the commit with the changes you want to include in the patch and select Create Patch from the context menu.

2. In the Patch File Settings dialog, specify the following details:

* The patch file location: choose the default location or select the To clipboard option if you do not want to save the patch to a file.

* Base path: specify the path relative to which paths inside the patch file will be written. Normally, this is your project directory, but you may want to use a relative path, for example, if the modified files are stored inside your Git repository.

* Reverse patch: select this option if you want to create a patch that reverts the changes you have made.

* Encoding: select the encoding for the patch file from the drop-down list.

Procedure: Create a patch from a file

1. Select the necessary file in any view (the   Project tool window  (`Alt+1` (Windows), `⌘ 1` (macOS), `⌘ 1` (IntelliJ IDEA Classic (macOS)), `⌘ 1` (macOS System Shortcuts), `Alt+1` (XWin), `Alt+1` (GNOME), `Alt+1` (KDE), `Alt+1` (Emacs), `Alt+1` (Sublime Text), `⌘ 1` (Sublime Text (macOS)), `Ctrl+1` (NetBeans), `Ctrl+Alt+L` (Visual Studio), `⌘ ⌥ L` (Visual Studio (macOS)), `Alt+1` (Eclipse), `Alt+1` (Eclipse (macOS))) , the editor, the  Commit window , and so on).

2. Select Git | Selected File | Show History from the main menu or Git | Show History 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.

3. Right-click a revision and choose Create Patch from the context menu.

Procedure: Apply patches

1. In the main menu, select:

* `Git | Patch | Apply patch` to choose a saved `.patch` file.

* `Git | Patch | Apply patch from Clipboard` if you have copied the content of a patch file. For example, this is convenient when you receive a patch by email and do not want to save it. For [Git format](https://git-scm.com/docs/git-format-patch) patches, IntelliJ IDEA extracts the commit message and the author and automatically fills the corresponding fields in the Commit tool window (`Alt+0` (Windows), `⌘ 0` (macOS), `⌘ 0` (IntelliJ IDEA Classic (macOS)), `⌘ 0` (macOS System Shortcuts), `Alt+0` (XWin), `Alt+0` (GNOME), `Alt+0` (KDE), `Alt+0` (Emacs), `Alt+0` (Sublime Text), `⌘ 0` (Sublime Text (macOS)), `Alt+0` (NetBeans), `Alt+0` (Visual Studio), `Alt+0` (Visual Studio (macOS)), `Alt+0` (Eclipse), `⌘ 0` (Eclipse (macOS)) ) .

2. In the Apply Patch dialog that opens, specify the path to the .patch file you want to apply.

> **Tip:**
> You can drag a file or an email attachment to any place in the editor.

3. If the source code was edited after a patch was created, conflicts may arise. To check if your patch can be applied without conflicts, click Show Diff ![the Show diff icon](https://resources.jetbrains.com/help/img/idea/2026.2/app-client.expui.vcs.diff.svg) `Ctrl+D` (Windows), `⌘ D` (macOS), `⌘ D` (IntelliJ IDEA Classic (macOS)), `⌘ D` (macOS System Shortcuts), `Ctrl+D` (XWin), `Ctrl+D` (GNOME), `Ctrl+D` (KDE), `Ctrl+D` (Emacs), `Ctrl+D` (Sublime Text), `⌘ D` (Sublime Text (macOS)), `Ctrl+D` (NetBeans), `Ctrl+D` (Visual Studio), `⌘ D` (Visual Studio (macOS)), `Ctrl+D` (Eclipse), `⌘ D` (Eclipse (macOS)). If there are conflicts, the corresponding lines will be highlighted in red.

4. If necessary, click ![](https://resources.jetbrains.com/help/img/idea/2026.2/app.expui.nodes.copyOfFolder.svg) Change Directory Paths and choose:

* Map Base Directory: specify a directory relative to which file names in the patch file will be interpreted. You can map the base directory to a single file, directory, or selection.

* Remove Leading Directory: apply the changes to files located in different directories from the ones specified in the patch. Clicking this button removes one slash in the path to the target file. Click the button as many times as many leading directories you need to remove. The number of removed slashes is indicated in square brackets.

* Remove All Leading Directories: remove all leading directories with one click and apply the patch to the file with the specified name in the base directory.

* Restore Leading Directory: revert the last Remove Leading Directory action. Click the button as many times as many previously stripped leading directories you need to restore.

* Restore All Leading Directories: revert the Remove All Leading Directories action.

5. Select the changelist to which you want to apply the patch or specify the name of a new changelist in the Name field, and enter a comment to this changelist (optionally).

6. If you want to make this changelist active, select the Set active option.

7. If you want IntelliJ IDEA to save the context of a task associated with the new changelist when deactivated and restore the context when the changelist becomes active, select the Track context option (refer to [tasks and contexts](managing-tasks-and-context.html) for details).

8. If you are applying a patch from the clipboard, you can select the Analyze and apply patch from clipboard on the fly option for IntelliJ IDEA to automatically detect patches in clipboard contents and suggest applying them.

9. If you want to move the patch to a temporary storage (shelf) before applying it, click Import to shelf (for more information, refer to [Shelve or stash changes](shelving-and-unshelving-changes.html)). Otherwise, click OK.

