Skip to content
Versora

Manual

Changes

Creating and applying patches

11 min read

On this page

A patch is a diff saved as text: what changed in each file, line by line. With it you take a change to another repository, send a fix by email or chat, or keep an experiment without creating a branch.

Versora creates patches in two ways (from a whole commit and from a file's changes) and applies them in two (from a .patch/.diff file and from the clipboard). Applying from the clipboard is the most complete: it shows the files first, says whether the patch applies and offers 3-way when it doesn't fit directly.

You want to…Use
Export a commitCreate patch from commit… (commit or branch menu); on a merge commit, Create patch of the merge (against the first parent)…
Export a file's changesCreate patch from file changes… (file menu)
Export a stashExport as patch (stash menu; see Stash)
Apply a patch someone pasted in the chatApply patch from clipboard… or Ctrl+V
Apply a .patch or .diff fileApply patch… (branch menu)

Tip

Applying a patch in Versora brings only the changes into your working directory. No commit is created, not even when the patch came from a git format-patch, with author and message. After applying, you review, stage and commit as usual.

Create a patch from a commit

Saves to a .patch file everything a commit changed, with the author, the date and the message, in the git format-patch format. Whoever receives it can apply only the changes (as Versora does) or recreate the commit with git am.

Where to find it

  • Commit menu in the graph: Create patch from commit…
  • Menu of a local or remote branch: Create patch from commit… (exports the branch's tip commit).

Step by step

  1. Right-click commit a1b2c3d in the graph.
  2. Choose Create patch from commit….
  3. In the Create patch from commit window, choose the folder. The suggested name is the commit's short SHA: a1b2c3d.patch.
  4. Click save. "Patch saved to C:\Patches\a1b2c3d.patch" appears.

What Versora does in git

bash
git format-patch -1 --stdout a1b2c3d > a1b2c3d.patch

The file is written with each file's original bytes: a file in Windows-1252 stays Windows-1252 inside the patch (see Legacy encodings). Nothing changes in the repository.

How to undo

There's nothing to undo in the repository. To discard the patch, delete the saved file.

Caveats and messages

  • For a merge commit, the item has a different name: see "Create a patch from a merge commit" below.
  • To export several consecutive commits at once, use git format-patch <start>..<end> in the terminal (see the git format-patch (opens another site) documentation).

See also

Create a patch from a merge commit

git format-patch skips merge commits: on its own, it would produce an empty file. That's why, on a merge commit, Versora generates the patch against the first parent: what the merge brought into the branch it was made on (the same changes the commit details show). The file has the same format, with the merge's author, date and message, and can be applied with git am: it becomes a single commit, without the second parent. The history of the branch that came in through the merge doesn't go along.

Where to find it

  • Menu of a merge commit in the graph: Create patch of the merge (against the first parent)…
  • Menu of a local or remote branch whose tip is a merge commit: the same item, instead of Create patch from commit…

Step by step

  1. Right-click merge commit 9f8e7d6 in the graph.
  2. Choose Create patch of the merge (against the first parent)….
  3. The save window has the title "Create patch of the merge: the changes it brought into the first parent (4c3b2a1)", with the first parent's short SHA. The suggested name is 9f8e7d6.patch.
  4. Click save. The notice says: "Patch saved to C:\Patches\9f8e7d6.patch. It's a merge: the patch has the changes it brought into the first parent (4c3b2a1) and, when applied, becomes a single commit, without the second parent."

What Versora does in git

bash
git log -1 --format=email 9f8e7d6                                     # header: author, date, subject
git diff --binary --patch-with-stat --no-ext-diff 9f8e7d6^1 9f8e7d6   # the changes against the first parent

The app joins the header and the diff in a single file, separated by ---, like a git format-patch. Whoever receives it recreates the commit with git am 9f8e7d6.patch, or applies only the changes with Apply patch…. Nothing changes in the repository.

How to undo

There's nothing to undo in the repository. To discard the patch, delete the saved file.

Caveats and messages

  • The patch carries the merge's result for the first parent, not the commits of the other branch. To take those commits one by one, export each one with Create patch from commit… or use cherry-pick.
  • To see first what goes into the patch, compare the merge with the first parent (see Comparing).

Create a patch from a file's changes

Saves a single file's diff to a .patch, the way it appears in the list you clicked: the unstaged changes, the staged ones, a whole new file or what a commit changed in it.

Where to find it

  • File menu, in any file list: Create patch from file changes…

Step by step

  1. In the changes panel (or in a commit's file list), right-click src/login.ts.
  2. Choose Create patch from file changes….
  3. In the Create patch from file changes window, confirm the suggested name, login.ts.patch, and save.
  4. "Patch saved to C:\Patches\login.ts.patch" appears.

What goes into the patch

List you clicked inDiff savedEquivalent command
Unstaged filesWhat is on disk and hasn't been staged yet.git diff -- src/login.ts
Unstaged files (new file)The whole file, as new.git diff --no-index -- /dev/null notas.txt
Staged filesWhat goes into the next commit.git diff --cached -M -- src/login.ts
A commit's listWhat that commit changed in the file.git diff -M <parent> <commit> -- src/login.ts

What Versora does in git

It asks git for the diff (table above) and writes the result to the chosen file, with the file's original bytes. Nothing changes in the repository.

How to undo

There's nothing to undo in the repository.

Caveats and messages

  • "There are no content changes to create a patch from.": the file only changed in mode or name, with no text difference. No save window opens.
  • The patch comes out with git's default context (usually 3 lines) and with the whitespace, even if the diff on screen has another number of context lines or Ignore whitespace on. That way it always applies back.
  • Binary files: the patch only records that the file changed and can't be used to apply it.

See also

Apply a patch from the clipboard

Opens the Apply patch window with the copied text. Before applying, it shows the files the patch touches, with the added and removed lines of each one, and says whether it applies directly, only with 3-way or doesn't apply. Nothing is applied without your click.

Where to find it

  • Shortcut: Ctrl+V with a patch copied, outside a text field.
  • Palette (Ctrl+P): "Apply patch from clipboard…".
  • // WIP row menu in the graph: Apply patch from clipboard…
  • Menu of a local branch: Apply patch from clipboard…

Step by step

  1. Copy the patch (from an email, from the chat, from a git diff in the terminal, from a .patch file open in the editor).
  2. With the repository open and the focus outside any text field, press Ctrl+V (or use the palette).
  3. The Apply patch window opens with the text in the Patch text field. You can paste another one (Ctrl+V in the field) or edit the text right there.
  4. A moment after you stop typing, the window checks the patch ("Checking the patch…") and shows the result and the Files in the patch list: each file with the new, deleted, renamed or modified mark and the counts (+12 −3, or binary).
  5. Click Apply (or Apply with 3-way, when that's the remaining way). Ctrl+Enter also works ("Apply to the working directory (Ctrl+Enter)").
  6. The toolbar shows "Applying the patch…" and, at the end, "Patch applied to 2 files". The files appear in Unstaged files.

The check results

MessageWhat it meansButton
"Applies cleanly."The patch fits the files as they are.Apply
"Applies cleanly (the text came with CRLF and will be applied with LF)."The copied text came with Windows line endings (from a web page or an email); Versora switches them to LF to apply.Apply
"Doesn't apply directly, but applies with 3-way: hunks that don't fit become conflicts for the conflict editor."The files changed since the patch was made, but git can do a three-way merge.Apply with 3-way
"Doesn't apply to this repository, not even with 3-way."Not even 3-way solves it. git's output appears in a box below, saying where it failed.Disabled
"This text isn't a patch git recognizes."The text doesn't look like a diff.Disabled
"No patch yet."The field is empty.Disabled

With a patch from git format-patch, the window adds "(git format-patch format: only the changes go in; no commit is created)".

What Versora does in git

bash
# List of the files and the counts
git apply --numstat -z -
git apply --summary -

# Check: directly and, if that fails, with 3-way (nothing is written)
git apply --check --whitespace=nowarn -
git apply --check --whitespace=nowarn --3way -

# Applying
git apply --whitespace=nowarn -          # only the working directory
git apply --whitespace=nowarn --3way -   # with 3-way: also touches the stage

The patch goes to git through standard input (-). If the text came with CRLF and only applies with LF, Versora converts it first. With 3-way, the hunks that don't fit become conflicts: the file appears in the Conflicted section, with the markers, and you resolve it in the conflict editor.

How to undo

Ctrl+Z undoes the application ("Undo: Apply patch (Ctrl+Z)"). Before applying, Versora keeps a copy of the files the patch changes, deletes or renames, and undo puts them back as they were (including their stage).

  • Files the patch created aren't in the copy: after Ctrl+Z they stay on disk, as new files. Discard them if you don't want them (see Discarding changes).
  • A patch that only creates files doesn't go into undo: discard the new files.
  • The undo refusal rules (files changed again, repository changed outside the app, operation in progress) are the same as for discards: see Undoing a discard.

Caveats and messages

  • "Patch applied with 3-way: 1 file is conflicted.": resolve the files in the Conflicted section before committing.
  • The patch is applied to the current working directory, whatever branch you right-clicked.
  • Ctrl+V only opens the window when the copied text looks like a patch (it starts with diff --git, --- a/, --- /dev/null, From <sha> or Index: and has @@ hunks or new, deleted, renamed or binary file marks). Otherwise, Ctrl+V works as usual.
  • Ctrl+V doesn't open the window in a text field, in the integrated terminal, with a dialog, Preferences or the palette open, or on Home.
  • If Windows doesn't let the app read the clipboard, the window opens empty, ready for you to paste with Ctrl+V.
  • Esc, Cancel or a click outside the window close it without applying.
PreferenceWhereDefault
Ctrl+V opens the patchPreferences › Operations › Warnings › Pasting a patch ("With a patch on the clipboard, Ctrl+V outside a text field opens "Apply patch from clipboard".").On

The Ctrl+V of this feature is a fixed key in the shortcut map ("Paste a copied patch (opens the apply patch window)"): it can't be changed; to turn it off, use the preference above.

For IT

The Operations page of Preferences can be hidden or locked by the company policy (preferences.hidden / preferences.locked, id ergoOps). See Company policy.

See also

Apply a patch file

Applies a .patch or .diff file saved on disk, directly, without the preview window.

Where to find it

  • Menu of a local branch: Apply patch…

Step by step

  1. Right-click a local branch (for example, the current one) and choose Apply patch….
  2. In the Apply patch window, choose the file (the filter shows .patch and .diff).
  3. The toolbar shows "Applying patch…" and, at the end, "Patch applied". The changes appear in Unstaged files.

What Versora does in git

bash
git apply --whitespace=nowarn C:/Patches/a1b2c3d.patch

git apply is all or nothing: if a hunk doesn't fit, no file changes and git's message appears in the error notice. There's no 3-way this way.

Before applying, the app asks git for the list of files in the patch, for the undo copy:

bash
git apply --numstat -z C:/Patches/a1b2c3d.patch    # the paths the patch touches (both sides of a rename)

If git can't read the patch, the error already appears here, before any file changes.

How to undo

Ctrl+Z undoes the application ("Undo: Apply patch (Ctrl+Z)"). Before applying, Versora keeps a copy of all the files the patch touches, and undo:

  • puts back the changed, deleted or renamed files as they were;
  • deletes the files the patch created, including when the patch only creates files.

The refusal rules are the same as for discards: if you edited one of those files again after applying, undo refuses instead of running over it. See Undoing a discard.

Caveats and messages

  • The patch is applied to the current working directory, whatever branch you clicked.
  • If the patch doesn't apply, or if you want to see the files first: open the file in the editor, copy its contents and use Apply patch from clipboard…, which checks first and offers 3-way.
  • A git format-patch patch applied this way also brings only the changes, without creating the commit.

See also