#TIL 2 - Create and apply git patch from a commit hash

Aug 12, 2020 · Dung Huynh

What

Create a patch from one branch and apply it to another branch.

Why

Cherry-pick commits when direct merge isn't possible or desired.

How

git checkout master
git format-patch -1 COMMIT_HASH
git checkout WORKING_BRANCH
git am FILE_PATH
  • format-patch -1: creates patch file for single commit
  • am: applies patch file (commit message preserved)