timhwang21.gitbook.io
  • Intro
  • Blog
    • 2023
    • 2022
    • 2021
    • 2020
    • 2019
  • CLI
    • Git
      • Bulk resolve merge conflicts
      • git rebase-onto
      • Patch from diff
    • Shell
      • Recipes
    • Vim
      • Batch editing
      • Buffers
      • <Ctrl-r>
      • External commands
      • :global
      • Help
      • Registers
      • Splits
    • Tools
  • Programming
    • React
      • Testing Styled Components
    • Typescript
      • curryRecord
      • Exhaustive conditionals with ADTs
      • newtype
      • OmitTypes
      • Safe JSON clone
      • Type inferrers
      • XOR type
    • Ruby
      • Pry
      • RSpec
    • Rails
      • Attributes
      • Cheap many to many
      • (Don't use) counter cache
    • Databases
      • Metrics
      • Testing indexes
  • Personal
    • Uses
    • Github
    • Medium
    • LinkedIn
    • Photography
Powered by GitBook
On this page
  1. CLI
  2. Git

Patch from diff

Normally when using git apply, you first generate a patch file with git format-patch. However, sometimes you want to send a quick diff to someone with git diff FILE | pbcopy.

Trying to pipe this into git apply will give a "corrupt patch" error, because git diff doesn't give the trailing newline that git format-patch does. We can fix this by wrapping in echo:

git diff FILE | pbcopy
# send to coworker; coworker runs following
echo "$(pbpaste)" | git apply
Previousgit rebase-ontoNextShell

Last updated 3 years ago