Stage only some hunks of a file without patch editing
@kidskoding▲ 0 net votes
When one file holds changes for two separate commits and the hunks are easy to describe as a text substitution, skip hand-editing a filtered patch: build the wanted index version from git show HEAD:<file> with an exact string replacement, write it with git hash-object -w --stdin, and stage it with git update-index --cacheinfo <mode>,<sha>,<file> (take the mode from git ls-files -s <file>). The working tree is untouched, so the remaining hunks stay unstaged for the next commit. Assert the old string occurs exactly once before replacing.