generating-patches
Scannednpx machina-cli add skill oaustegard/claude-skills/generating-patches --openclawGenerating Patches
Generate portable git patch files from codebase modifications, enabling users to apply Claude's edits to their local repositories.
When to Use
Activate after modifying files in an uploaded codebase when the user needs to transfer changes back to their local environment. Typical workflow: user uploads zip → Claude edits files → this skill exports changes as a patch.
Prerequisites
Verify git is available and the working directory is a git repository (or can be initialized as one):
git status 2>/dev/null || git init
If working with an uploaded codebase that lacks git history, initialize and create a baseline commit before making edits:
git init
git add -A
git commit -m "Baseline: original uploaded state"
Generating the Patch
After completing edits, generate a unified diff:
# For uncommitted changes (working tree modifications)
git diff > /mnt/user-data/outputs/changes.patch
# If changes are staged but not committed
git diff --cached > /mnt/user-data/outputs/changes.patch
# For both staged and unstaged
git diff HEAD > /mnt/user-data/outputs/changes.patch
For committed changes (preserves commit messages and metadata):
# All commits since baseline
git format-patch --stdout baseline..HEAD > /mnt/user-data/outputs/changes.patch
# Or specify number of commits
git format-patch --stdout -n 3 > /mnt/user-data/outputs/changes.patch
Handling Edge Cases
Binary files: Git diff excludes binaries by default. Warn the user if binary files were modified:
git diff --name-only --diff-filter=M | xargs file | grep -v "ASCII\|UTF-8\|empty"
Large patches: For extensive changes, consider splitting by directory or file type:
git diff -- "*.py" > /mnt/user-data/outputs/python-changes.patch
git diff -- src/ > /mnt/user-data/outputs/src-changes.patch
No changes detected: Verify files were actually modified. Common issues:
- Edits made to copies outside the git tree
- Files not tracked by git (need
git addfirst)
Output Requirements
Always output to /mnt/user-data/outputs/ with a descriptive filename. Provide the download link:
[Download changes.patch](computer:///mnt/user-data/outputs/changes.patch)
User Instructions
Include these instructions with every patch delivery:
To apply this patch locally:
cd /path/to/your/repo
# Preview changes (dry run)
git apply --check changes.patch
# Apply to working tree
git apply changes.patch
If using format-patch output (includes commit metadata):
git am changes.patch
Troubleshooting:
git apply --reject changes.patch— applies what it can, writes.rejfiles for conflictsgit apply -R changes.patch— reverses a previously applied patchgit apply --3way changes.patch— enables three-way merge for conflicts
Optional: PR Description
When requested, generate a pull request description from the patch:
# Extract summary of changes
echo "## Summary"
git diff --stat
echo ""
echo "## Changes"
git diff --name-only | while read f; do echo "- \`$f\`"; done
Combine with a brief description of what was changed and why, suitable for GitHub PR body.
Source
git clone https://github.com/oaustegard/claude-skills/blob/main/generating-patches/SKILL.mdView on GitHub Overview
This skill exports changes from an edited codebase as portable git patch files. It enables you to apply Claude's edits to your local repository, preserving change history when possible.
How This Skill Works
After edits, it checks the repo state and generates patches using git diff for uncommitted changes or git format-patch for commits, saving to /mnt/user-data/outputs with a descriptive filename. If the uploaded codebase lacks history, it initializes a new git repo and creates a baseline commit before edits.
When to Use It
- You edited an uploaded codebase and need to export changes back to your local environment.
- You want to transfer changes without pushing to a remote repository.
- You need to preserve commit messages and metadata when sharing changes.
- You have uncommitted working-tree changes that should be exported as a patch.
- You want to split a large set of changes into smaller patches for easier review.
Quick Start
- Step 1: Ensure git is installed and your working directory is a git repo; initialize it and create a baseline commit if needed.
- Step 2: Make edits, then generate the patch: for uncommitted changes, git diff > /mnt/user-data/outputs/changes.patch; for staged changes, git diff --cached > /mnt/user-data/outputs/changes.patch; for all changes, git diff HEAD > /mnt/user-data/outputs/changes.patch. If you used commits, run git format-patch --stdout baseline..HEAD > /mnt/user-data/outputs/changes.patch.
- Step 3: Download the patch and apply locally: [Download changes.patch](computer:///mnt/user-data/outputs/changes.patch). To apply: git apply changes.patch or, for format-patch, git am changes.patch.
Best Practices
- Verify git is available and the working directory is a repo; initialize if needed and create a baseline commit before edits.
- Choose the right diff method: git diff for uncommitted changes, git diff --cached for staged changes, git diff HEAD for both, or use git format-patch to preserve commits.
- Name the patch file descriptively and ensure it is saved to /mnt/user-data/outputs with a descriptive filename (e.g., changes.patch).
- For binary files or very large patches, split by directory or file type and warn about binaries.
- Test patch application with git apply --check or git am before distribution.
Example Use Cases
- A user uploads a codebase, Claude edits files, and exports changes as changes.patch to download and apply locally.
- A bug fix in a local clone is exported as a patch to share with teammates via changes.patch.
- A large refactor is split into per-directory patches like python-changes.patch and src-changes.patch.
- Uploaded codebase has no history; a baseline commit is created, and the patch preserves changes with a descriptive filename.
- To apply on another clone, use git apply for generic diffs or git am for format-patch patches.