Forrest logo
back to the git tool

git-stash:tldr:34a62

git-stash: Apply a stash (default is the latest, named stash@{0}).
$ git stash apply ${optional_stash_name_or_commit}
try on your machine

The git stash apply command is used to apply a stash to your working directory and index, restoring the changes that were stashed away.

When you run git stash apply, Git looks for the most recent stash and tries to apply it. However, sometimes you may have multiple stashes saved, in which case you need to specify the stash you want to apply.

The ${optional_stash_name_or_commit} is a placeholder indicating that you can provide either the name of the stash or the commit hash of the stash you want to apply. If you don't provide any name or commit hash, Git will apply the most recent stash.

For example:

  1. If you want to apply the most recent stash, you can simply run git stash apply.
  2. If you want to apply a specific stash, you can run git stash apply stash@{n}, replacing n with the index of the stash you want to apply. For instance, git stash apply stash@{2} will apply the second most recent stash.
  3. Alternatively, you can use the commit hash of the stash instead of its name. For example, git stash apply abcd1234 will apply the stash with the commit hash "abcd1234".

By default, git stash apply leaves the stash intact, meaning it doesn't remove the stash from the stash list. If you want to remove the applied stash from the stash list as well, you can use git stash drop ${stash_name_or_commit}.

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