Partial git apply
git
Solution
Since git version 1.7.12, `git apply` has a `--3way` (or `-3`) option which will:
- Apply any changes it can figure out and stage them (i.e.: add them to the working tree and index),
- Add any new files and stage them (i.e.: add them to the working tree and index), and,
When it encounters a merge conflict, it will, for each conflicting hunk:
- Put the code from the branch you are patching between `<<<<<<< ours` and `=======` markers, and,
- Put the code from the patch file between `=======` and `>>>>>>> theirs` markers.
... files with conflicts will not be staged: you'll have to manually fix them and `git add` them afterwards.
Problem
How can I get `git apply --index` to not abort completely just because a single hunk fails? I have a 100K+ patch with dozens of files deleted and added, it'd be a pain to do the `patch -p1`, `git add`, `git rm` dance manually. Edit: `git apply --reject --index` seems to do two thirds of the work: the patch is applied and removed files are staged for deletion but new files are not added.