![Forrest logo](/images/logo.png)
git-stash:tldr:34a62
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:
- If you want to apply the most recent stash, you can simply run
git stash apply
. - If you want to apply a specific stash, you can run
git stash apply stash@{n}
, replacingn
with the index of the stash you want to apply. For instance,git stash apply stash@{2}
will apply the second most recent stash. - 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}
.