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