Support for format-patch

This PR adds support for ```git format-patch``` behaviour. This is something we need to have for rebases  #2253 and core git compatibility (```git rebase``` uses ```git am```).

It currently cannot generate a "patch" for merge commits (depends on #1965) or binary files.