mirror of
https://github.com/mike-rambil/Advanced-Git.git
synced 2025-12-30 14:09:30 -06:00
1.3 KiB
1.3 KiB
⬅️ Back to Sharing Changes as Patch Files
Create Patch from Last Commit(s)
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
- Create patch files for the last two commits.
git format-patch -2
- Create patch files for all commits since main.
git format-patch -2 origin/main..HEAD
Steps
- Run '
git format-patch HEAD~1' to create a patch for the last commit. - 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.
Links
➡️ See the Next Step: Apply Patch with Commit Metadata
Author: mike-rambil • Updated: 2024-06-10 • Tags: patch, format-patch, committed