Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save aont/7cc00c5c765fea1975e1486beb32fc2d to your computer and use it in GitHub Desktop.

Select an option

Save aont/7cc00c5c765fea1975e1486beb32fc2d to your computer and use it in GitHub Desktop.

Applying Codex-Generated Patches on Windows (MSYS2)

When Codex proposes code changes, it can output them in two handy formats: a patch (diff) or a shell snippet that runs git apply. On Windows with MSYS2, the clipboard and character encodings can get in the way—especially if your system locale uses CP932 (Shift_JIS). Below are two simple one-liners you can run in MSYS2 to apply those changes safely.

1) Apply changes from “Copy patch” (a raw diff)

Use this when you clicked “Copy patch” in Codex and your clipboard now contains a unified diff:

msys2$ powershell.exe Get-Clipboard | iconv -f CP932 -t UTF-8 | tr -d '\r' | git apply -v --3way -
# or
msys2$ win32yank -o --lf | git apply -v --3way -

What it does

  • powershell.exe Get-Clipboard reads the text you copied from Codex.
  • iconv -f CP932 -t UTF-8 converts from Windows CP932 to UTF-8 so Git parses the diff correctly.
  • tr -d '\r' strips Windows \r\n line endings to POSIX \n.
  • git apply -v applies the patch to your working tree and prints verbose output.

Tips

  • Run it from the root of your Git repo.
  • If you see path mismatches, add -p0/-p1 to git apply as needed.
  • For a dry run first: git apply --check -v.

2) Apply changes from “Copy git apply” (a shell snippet)

Use this when you clicked “Copy git apply” in Codex and your clipboard now contains a shell command that itself runs git apply:

msys2$ powershell.exe Get-Clipboard | iconv -f CP932 -t UTF-8 | tr -d '\r' | sh
# or
msys2$ win32yank -o --lf | sh

What it does

  • Reads the Codex-generated shell script from the clipboard.
  • Converts CP932 → UTF-8 and normalizes line endings.
  • Pipes the cleaned script to sh, which executes it (usually invoking git apply with the right flags).

Tips

  • Inspect the clipboard content if you’re unsure: powershell.exe Get-Clipboard | iconv -f CP932 -t UTF-8 | sed -n '1,60p'
  • If the snippet creates files or uses paths, run it at the repo root.

Why the extra plumbing?

Windows often stores clipboard text in CP932 and uses CRLF line endings. Git and POSIX tools expect UTF-8 with LF. The iconv + tr steps remove encoding and newline pitfalls so git apply can do its job reliably.

Quick Checklist

  • ✅ Copy from Codex (Copy patch or Copy git apply)
  • ✅ In MSYS2, run the matching one-liner above
  • ✅ Confirm with git status
  • ✅ Commit the changes when satisfied

That’s it—you can smoothly apply Codex’s suggestions on Windows without wrestling with encodings or line endings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment