Create a Stash
Save current changes to stash.
git stash
Stash with a message:
git stash save "Work in progress on feature X"
Stash including untracked files:
git stash -u
Stash everything including ignored files:
git stash -a
List Stashes
View all stashed changes.
git stash list
The output shows entries like stash@{0}, stash@{1}, etc.
Apply a Stash
Apply most recent stash without removing it.
git stash apply
Apply specific stash:
git stash apply stash@{2}
Pop a Stash
Apply most recent stash and remove it from stash list.
git stash pop
Pop specific stash:
git stash pop stash@{1}
Show Stash Contents
View changes in most recent stash.
git stash show
Show detailed diff:
git stash show -p
Show specific stash:
git stash show stash@{1} -p
Drop a Stash
Delete most recent stash.
git stash drop
Delete specific stash:
git stash drop stash@{2}
Clear All Stashes
Remove all stashed entries.
git stash clear
Create Branch from Stash
Create a new branch from stashed changes.
git stash branch <branch-name>
This applies the stash and drops it from the stash list.
Stash Specific Files
Stash only specific files.
git stash push -m "message" <file1> <file2>
Stash Partial Changes
Interactively choose which changes to stash.
git stash -p
Apply Stash to Different Branch
Switch branch and apply stash.
git checkout <branch-name>
git stash apply
Recover Dropped Stash
Find dropped stash using reflog.
git fsck --unreachable | grep commit
git show <commit-hash>
Apply the recovered stash:
git stash apply <commit-hash>