`git stash --patch` enables selective stashing, giving control over what changes are saved. It prompts for each change (hunk) with options to stash, skip, or quit. This is useful for separating unrelated modifications in different files. Hunks can be split into smaller parts with the `s` option for finer-grained control. `git stash -p` can be combined with `--keep-index` to preserve staged files or with path specifiers to target specific file types. Named stashes can be created with `save "name"` for better organization. The `--include-untracked` option allows stashing new files. Partial stash undoing can be achieved using `git stash show -p | git apply -R`. Stash conflicts can be resolved in smaller chunks using `git stash apply --index`. Stashes can be shared as patch files using `git stash show -p > file.patch`.
dev.to
dev.to
