Files
Advanced-Git/contents/create-patch-from-last-commit-s.md
2025-07-09 01:19:53 +00:00

1.1 KiB

⬅️ Back to Sharing Changes as Patch Files

Create Patch from Last Commit(s)

Category: Patch & Diff

Command

git format-patch HEAD~1

Examples

  • Create a .patch file for the last commit.
git format-patch HEAD~1
  • Create a single patch file for all commits on top of main.
git format-patch origin/main..HEAD --stdout > my-changes.patch

Steps

  1. Run 'git format-patch HEAD~1' to create a patch for the last commit.
  2. Use 'git format-patch origin/main..HEAD --stdout > my-changes.patch' to create a single patch file for multiple commits.

Warnings

  • ⚠️ Patch files created this way include commit messages, authorship, and timestamps.
  • ⚠️ Use 'git am' to apply these patches on another system.

Tags

patch, format-patch, committed

Author

mike-rambil

Last Updated

2024-06-10

➡️ See the Next Step: Apply Patch with Commit Metadata