How to merge/appy file and file content diff hunk by hunk with `git add --patch` interface
01:02 05 Jun 2026

So far I figured out how to show diff:

diff -u "$old_file" <(echo "$new_file_content")
# or
git diff --no-index "$old_file" <(echo "$new_file_content")

Then if I'm happy with changes I can echo "$new_file_content" > "$old_file". But sometimes I want to only merge a chunk of diff.

In context of git repository I like to use git add --patch file (I only use y/n/s, s is to split into smaller chunks). "Stage this hunk".

Ideally I would like to have same interface as git add --patch to merge some parts from diff, with as smaller chunks/hunks as possible. If it is not possible to use git for this purpose then important part for my use-case in git add --patch is:

  1. Ability to add/merge chunk/hunk or skip
  2. Ability to split chunk/hunk to smaller piece

I have tried patch --merge=merge but it doesn't bring interactive menu. I have also tried nvim -d but it was very confusing to me as not experienced vim user and I didn't managed to merge single file.

git merge patch git-diff git-add