Interactive patch from external .diff file

两盒软妹~` 提交于 2021-01-29 04:20:56

问题


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?


回答1:


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?




回答2:


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.



来源:https://stackoverflow.com/questions/40970466/interactive-patch-from-external-diff-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!