Scenario: I have a patch file that applies cleanly to my working files, but I do not want all the changes from the patch.
Usually, I do vim example.patch
, remove unwanted changes and them apply patch -p0 -i example.patch
but at times the patch does not apply cleanly, and I have to start over again.
Is there a patch file editor that allows users to edit and delete part of the patch and still can apply cleanly ?
Don't edit patch files manually. In your case, you can try some interactive tool to apply your patch hunk by hunk, like ipatch
What SCM do you use? if using Git you can:
Before generating the actual patch use
git add -p
to only add parts of your changes. It is good practice to generate smaller commits with only related changes (however some organizations don't like this and only allow a mega commit).If you already have the patch apply it then use
git add -p
to add the parts of the code you want to keep to your index. You can commit and throw away the rest (git co .
) or stash it (git stash
).edit (based on the git add -p comment)
git add -p
allows you to split a hunk into smaller pieces using the s option, in cases when you need more detail you need to use the e option to edit, that will take you to your gitconfig editor and it will have the instructions on how to edit the hunk.If you open a diff file in emacs and put the editor in "diff" mode you can actually edit patches and it will update the hunk markers in a smart way. Works really well for me!
If you are looking for a non-interactive solution,
rediff
frompatchutils
is of help.Here's its
man
description:Based on its description,
recountdiff
could also be a potential candidate to fix unified diffs.