stash
The git stash
command is used to temporarily save changes in your working directory that you are not ready to commit. This allows you to switch branches or perform other tasks without losing your current work. The stashed changes can be reapplied later.
Detailed Explanation
Stashing Changes: When you run
git stash
, Git saves the changes in your working directory and index (staging area) to a new stash entry and reverts your working directory to match the HEAD commit.Stash List: You can view the list of stashed changes using
git stash list
. Each stash entry is identified by a name likestash@{0}
,stash@{1}
, etc.Applying Stashed Changes: You can reapply stashed changes using
git stash apply
orgit stash pop
. Theapply
command reapplies the changes without removing the stash entry, whilepop
reapplies the changes and removes the stash entry.Dropping Stashes: You can remove a specific stash entry using
git stash drop
or clear all stashes usinggit stash clear
.
Examples
Stashing Changes:
git stashThis command stashes the current changes in your working directory and index.
Applying the Most Recent Stash:
git stash applyThis command reapplies the most recent stash entry without removing it from the stash list.