本文へスキップ
Skillpedia
一般的なプログラミング6.2k · #14386

apply-patch

できること

Gitを使って、一連のコード変更を1つのパッチとして適用します。3つ以上のファイルにまたがる変更が必要な開発者や、単純な編集がうまく一致しない開発者向けです。

使う場面

  • ✓1つの変更で、3つ以上のファイルの編集が必要なとき。
  • ✓テキストが一致せず、単純な置換の編集が失敗し続けるとき。
  • ✓プルリクエストやgit diffから来たパッチを適用したいとき。

スキルのリンク

https://github.com/agentscope-ai/agentscope-java/blob/main/agentscope-examples/agents/agentscope-codingagent/src/main/resources/workspace-templates/skills/apply-patch/SKILL.md

コピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。

使い方

いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。

貼り付け用メッセージ

このスキルを使って手伝ってください:https://github.com/agentscope-ai/agentscope-java/blob/main/agentscope-examples/agents/agentscope-codingagent/src/main/resources/workspace-templates/skills/apply-patch/SKILL.md このリンクのSKILL.mdファイルを読んで、私の作業でその指示に従ってください。
こういうスキルを、AIが自分で見つけてくれたら?無料のSkillpedia MCPをインストール。1行で、作業の前に15,000+のスキルから探してくれます。1分でインストール →

AIへの頼み方の例

“このモジュールの4つのファイルにわたる同じ名前の変更を、1つのパッチとして適用してください。先にきれいに適用できるか確認してください。”

毎週5つの新しいスキル。1分で読めます。

仕組み

スキルは、変更内容を表すunified diffを書き、それが適用できるかを確認してから、Gitで一度にすべてを適用します。パッチが拒否された場合、エージェントは現在の行を読み直して、パッチを作り直します。

技術的な内容(元のSKILL.md)

作者による元のテキスト(英語)をGitHubからそのまま表示しています。

Apply Patch

The built-in edit_file does an exact string match on a single file and has no fuzzy tolerance. For multi-file changes, or when edit_file keeps failing to find the string, construct a unified diff and apply it atomically with git.

Procedure

  1. Write the unified diff to a file in the sandbox (use write_file or a heredoc via execute):

    diff --git a/path/to/file b/path/to/file
    --- a/path/to/file
    +++ b/path/to/file
    @@ -10,7 +10,7 @@ context line
    -old line
    +new line
    
  2. Validate before applying: git apply --check changes.patch

  3. Apply: git apply changes.patch (use -p0 if paths are not a/...b/...).

  4. If git apply rejects the hunk, the surrounding context is stale — read_file the exact lines again, regenerate the diff with correct context, and retry.

When to prefer this

  • Editing 3+ files for one logical change (atomic, all-or-nothing).
  • Repetitive or whitespace-sensitive edits where edit_file exact-match struggles.
  • Re-applying a patch produced elsewhere (e.g. from a PR or git diff).

Always run the verify-changes skill afterwards.

よくある質問

適用の前にパッチを確認しますか?

はい。スキルは適用の前にパッチを確認します。

パッチが失敗したらどうなりますか?

エージェントは現在のファイルの行を読み直し、新しいパッチを作ります。

全部か無かですか?

パッチは1つの変更として適用されるため、全部か無かになるよう意図されています。

詳細

作者による元の説明

Apply multi-file or tricky edits atomically with git apply instead of many fragile edit_file calls. Use when changing several files at once or when edit_file fails to match.

repo: agentscope-ai/agentscope-java

人気

GitHubのスター
6.2k
ランキング
#14386
ライセンス
Apache-2.0
更新日
2026/11/2

このスキルは役に立ちますか?

0

ログイン して投票しましょう。

コメント

  • …

このリポジトリの他のスキル

似ているスキル