Forrest logo
back to the git tool

git-stash:tldr:f3245

git-stash: Interactively select parts of changed files for stashing.
$ git stash -p
try on your machine

The git stash -p command is used to interactively select parts of modified files to be stashed away in temporary storage called "stash" in Git.

The -p option stands for "patch" and allows you to review and choose specific changes or lines from the modified files that you want to stash. It initiates an interactive mode called the patch mode.

When you run git stash -p, Git will present you with a series of prompts for each hunk (a distinct section of changes) in the modified files. You can choose to apply or skip each hunk by entering specific commands. Here are some common commands used in the patch mode:

  • y or n: Apply the current hunk or skip it.
  • s or e: Split the current hunk into smaller hunks to allow more granular selection.
  • ?: Display help information on available commands.
  • q: Quit the patch mode without stashing any changes.
  • a: Apply all remaining hunks without further prompts.
  • d: Do not stash any of the remaining hunks.

By using the git stash -p command, you have more control over the specific changes you want to temporarily store in the stash rather than stashing the entire set of modifications.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the git tool