I am looking for a universal way to turn a patch file generated by git show
, git format-patch
or even diff
in a commit the best way possible.
I would expect the following features:
- Existing files should be modified and the modifications staged for the new commit.
- New files should be created and staged for the new commit.
- File deletions should be staged for the new commit as well.
- If the patch was created using
git format-patch
, commit message should be parsed and used for the new commit. - If the patch was created using
git show
, commit message should be parsed and used for the new commit. - If the patch was not created by the two tools above, it should still be processed.
- The CLI should be able to accept multiple patches and thus create multiple commits.
I am mostly interested in existing solutions before I consider creating a new tool.
Previous research:
The closest tool is git am
but fails #5 and #6 so it isn't useful for the purpose. On the other hand git apply
doesn't create a commit on its own and fails at least #2 and #5. I'm not aware of tools that would be more successful than those two.
When applying patches from RPM specfile in the following format:
Patch0: abc.patch
Patch1: xyz.patch
I'm currently building a script using the following sed command:
sed -re 's/.*: *(.*)/git apply \1 \&\& git add . \&\& git commit -am \1/'
This of course doesn't do #4 and #5 as it always uses patch filename as the commit message and #7 is worked around.