Of cleats and toenails« an older post
a newer one »Delight begets delight

Applying branch changes to a new branch in git


I am unsure how other people do this, but this is how I apply changes from one branch to a new branch when the original branch can't be rebased to master (say, when the original branch is thousands, or really, maybe just hundreds or tens of conflicting, commits behind master).

$ git co branch-no-longer-loved

If differences with master aren't causing rebase issues, can do this:

$ git rebase master
$ git diff master > ~/some-differences.diff

More likely, I'm doing this because I can't rebase to master. So, taking my changes back to where I diverged from master, say 3 checkins:

$ git diff HEAD~3 > ~/some-differences.diff

Applying the changes to a new branch with patch.

$ git co branch-that-is-now-favoured
$ patch -p1 < ~/some-differences.diff 

The branch-that-is-now-favoured branch now contains the changes from branch-no-longer-loved, as unadded and unstaged and unhistoried files, without having to fight with git to get things in there.

The -p1 in patch makes this easy.

Add new comment