agentsclimarketplace

Git patch workflow

Skill cxcscmu/SkillLearnBench/skills/b1-one-shot-claude-haiku-4-5/fix-security-bug/git-patch-workflow

Creating, managing, and applying unified diff patches with Git for source code modifications.From its SKILL.md

Install
npx -y skills add cxcscmu/SkillLearnBench --skill git-patch-workflow

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

SKILL.md

2.3 KB, 589 tokens by cl100k_base, as published. Nobody here has run it

Git Patch Workflow

Creating Patch Files

Method 1: From Unstaged Changes

cd /path/to/repo
git diff path/to/file.java > /path/to/patch/fix.patch

Method 2: From Staged Changes

git diff --cached > /path/to/patch/fix.patch

Method 3: From Commits

# Create patch from last N commits
git format-patch -N HEAD

# Create patch from specific commit
git show COMMIT_HASH > /path/to/patch/fix.patch

Patch File Structure

A unified diff patch looks like:

--- a/original/path/file.java
+++ b/modified/path/file.java
@@ -10,5 +10,6 @@ class MyClass {
     // context line
-    old code here
+    new code here
     // context line

Key components:

  • --- prefix: original file
  • +++ prefix: modified file
  • @@ markers: line numbers and context
  • - prefix: removed lines
  • + prefix: added lines
  • No prefix: context lines

Applying Patches

Basic Application

cd /path/to/repo
patch -p1 < /path/to/patch/fix.patch

With Error Handling

# Dry-run to test application
patch -p1 --dry-run < /path/to/patch/fix.patch

# Apply with strict checking
patch -p1 < /path/to/patch/fix.patch

# Apply with less strict checking
patch -p0 < /path/to/patch/fix.patch

Best Practices

  1. Use Git Format: Create patches via git diff or git format-patch for consistency
  2. Include Context: Ensure adequate context lines (3+ lines around changes)
  3. Test Patches: Always dry-run before applying to ensure compatibility
  4. Modular Patches: Create separate patches for logically independent changes
  5. Clear Names: Name patches descriptively (e.g., fix-javascript-security-bypass.patch)
  6. Document Changes: Include explanation of what the patch fixes

Verifying Application

# Check if patch was applied
git status
git diff HEAD

# Verify specific file was patched
git show HEAD:path/to/file.java | grep "your fix"

Multiple Patches

For multiple related patches:

# Create patches in order
git diff HEAD~2 HEAD~1 > patch1.patch
git diff HEAD~1 HEAD > patch2.patch

# Apply in sequence
patch -p1 < patch1.patch
patch -p1 < patch2.patch

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.