Skip to content

Add option to save generated patch to file #5117

@lixuan998

Description

@lixuan998

Is your feature request related to a problem? Please describe.

When working with the custom patch builder, lazygit currently allows copying the generated patch to the clipboard, but there is no built-in way to save the patch directly to a file.

This can be inconvenient when the patch needs to be reviewed later, shared with others, applied manually using git apply, or stored as a temporary artifact during a larger workflow.

At the moment, users have to copy the patch to the clipboard and manually paste it into a file, which is error-prone and interrupts the workflow.

Describe the solution you'd like

Add an option in the custom patch options menu to save the generated patch directly to a file.

Proposed behavior:

  • Add a “Save patch to file” option alongside the existing clipboard option
  • Prompt the user for a file path
  • Support both absolute and relative paths (with relative paths resolved from the repository root)
  • Write the generated patch content to the specified file
  • Show a confirmation toast after the file is successfully written

This would provide a smoother workflow for users who frequently need to export patches.

Describe alternatives you've considered

  • Copying the patch to the clipboard and manually pasting it into a file
  • Using external scripts or custom commands to capture the patch output

These approaches work but are less discoverable and less convenient than a built-in option.

Additional context

I have a working implementation that adds a new menu item to the custom patch options menu, prompts for a file path, saves the rendered aggregated patch to disk, and includes the necessary i18n strings.

If this feature is acceptable, I’m happy to open a PR with the implementation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions