Skip to content

Patch building

Take lines out of a commit, and put them somewhere else.

A custom patch holds lines that you take out of commits. You collect the lines first. Then you choose what stage does with them.

Use a custom patch when one commit contains two changes and only one of them belongs on this branch.

  1. Press 4 to focus the commits panel.
  2. Press enter on a commit. stage shows the files of that commit.
  3. Press space on a file.
The files of one commit. space takes the whole file.

A full dot marks a file that is in the patch. An empty dot marks a file that is not.

  1. Press enter on a file. stage shows the lines of that file.
  2. Press v to start a selection.
  3. Press j or k to extend the selection.
  4. Press space.
Part of a second file goes into the same patch.

One patch can hold whole files and parts of files at the same time.

Press esc to leave the file list. The patch is kept, and the footer says so. The commits panel shows the patch beside its commit.

You can collect from more than one commit into the same patch. Move to another commit, press enter, and take more files or more lines.

Press ctrl+p to open the patch options.

The options for a patch, with a modified working tree.

These options are always available:

Option Result
reset the custom patch The patch becomes empty. The commits keep their lines.
apply to worktree The lines are added to the working tree.
apply in reverse The lines are removed from the working tree.
copy patch to clipboard The patch text goes to the clipboard.

The options that rewrite history are hidden while the working tree has changes:

Option Result
remove from commit The lines leave the source commit.
move to the index The lines leave the commit and enter the index.
move to a new commit after A new commit holds the lines.
move to a new commit before A new commit holds the lines, before the source.
move to another commit The lines move to a commit you pick.

If you want these options, commit or stash your changes first. stage hides them instead of offering a command that refuses.

The options that rewrite history run as a rebase. A rebase can stop on a conflict, like any other rebase. Read Conflicts for the keys that continue it.

stage copies the custom patch of lazygit, and the keys of lazygit. One behavior is different. lazygit shows the history options on a dirty tree, and it stashes around the move-to-index command. stage hides them until the tree is clean.