To apply a patch hunk by hunk (interactively) like git add --patch, you can use the --interactive or -i flag with git apply. However, git apply does not natively support an interactive mode like git add -p or git checkout -p.
git checkout -p or git stash -pIf you want to selectively apply parts of a patch, the best approach is to use:
git checkout -p (or git restore -p in newer Git versions)orbashgit checkout -p <branch> -- <file> # For changes from a branch
bashgit stash show -p <stash> | git checkout -p --reverse -- <file> # For stashed changes
git stash apply -pbashgit stash apply -p
git diff + Manual Editingchanges.patch), you can:
bashgit apply --check changes.patch # Test if it applies cleanly git apply changes.patch
git add -p After Applyingbashgit apply changes.patch git add -p # Interactively stage hunks
git apply --interactive?git apply is designed for non-interactive patch application. It either applies the entire patch or fails.checkout -p, stash -p, or add -p.git checkout -p <branch> -- <file> or git stash apply -pgit add -pgit apply --check changes.patchgit apply changes.patchLe Chat can make mistakes. Check answers. Learn more