4

Is there a command or program for Linux that allows to patch the source code interactively, printing every chunk on the screen and waiting for acknowledgement before applying it to the file?

Something like git add -p, but taking the changes from another .diff file?

3
  • Git's add -p is part of a big perl script ($(git --exec-path)/git-add--interactive), so it would be easy (well...) to modify it to read some other diff.
    – torek
    Dec 5, 2016 at 15:57
  • Did you ever find a solution or write a script?
    – mcp
    Oct 22, 2020 at 19:41
  • @young_souvlaki sorry, did not have time to investigate in the direction of torek's hint. Will try it out maybe on the weekend.
    – Student4K
    Oct 23, 2020 at 11:48

2 Answers 2

2

You can always write script in shell/ruby/python that reads that file line by line and prompts adding diff between file signatures.

It can accept name of diff file as parameter or you can put two hashes and make a patch inside a script.

More so you can call that script git-command-name, put it in your user/bin folder and git will recognise command-name as git command.

On the other hand (just an idea) can you manipulate creation of .diff ? Maybe you can use format-patch and on applying stop after every commit diff?

0

Although not interactive, another option is to manually edit the .diff file and remove any changes you don't want.

If you open a diff file in emacs and put the editor in diff-mode you can edit patches and emacs will try to update the hunk markers. (Emacs will open .diff files in diff-mode automatically.)

To update markers manually after making changes do C-c C-w to regenerate the hunk.

To apply hunks one by one do C-c C-a. To reverse-apply do C-u C-c C-a. You can also M-x diff-tell-file-name to apply them to a different file.

I found patch original patch.diff to be more reliable than patch < patch.diff and patch files created with diff -u to be easier to work with.

Information also documented here.

UPDATE [5.21.21]:
C-c C-s lets you split up hunks which is very useful for manually editing. Sometimes C-c C-w (diff-ignore-whitespace-hunk) does not do what you intended, so the safest bet is to split the hunks and let emacs update the headers automatically. This is especially useful when keeping lines unchanged; just split into a hunk and delete to remove the change.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.