Last Updated: February 25, 2016
·
487
· benkitzelman

Git: patching diffs between branches

Recently I accidentally committed changes to master that I want to commit in a feature branch..... I made the mistake of
1. branching master (to a feature branch) from my erroneous commit - then
2. resetting (HARD) master to the previous commit

This axed all my history in my feature branch as the branching commit in master no longer existed....

To fix I had to create a new feature branch from master, then cherrypick the diffs between master and my original feature branch.... to do so I patched using the following:

git checkout master
git checkout -b [new_feature_branch]
git diff --no-prefix origin/[busted_feature_branch] > my.patch

then apply the patch:

patch -p0 < my.patch