Stash Commands
Temporarily save uncommitted changes so you can work on something else, then restore them later. Perfect for quick context switches.
When to Use Stash
Use stash when you need to quickly switch branches but aren't ready to commit. Your changes are saved on a stack and can be reapplied at any time.
Quick Reference
dits stash # Save changes
dits stash pop # Restore and remove
dits stash apply # Restore but keep
dits stash list # Show all stashes
dits stash drop # Delete a stash
dits stash clear # Delete all stashesdits stash
Save your current changes to the stash stack:
Synopsis
dits stash [push] [-m <message>] [--] [<pathspec>...]
dits stash list
dits stash show [<stash>]
dits stash pop [<stash>]
dits stash apply [<stash>]
dits stash drop [<stash>]
dits stash clearOptions
-m, --message <msg> Add description to stash
-u, --include-untracked Include untracked files
-a, --all Include ignored files too
-k, --keep-index Keep staged changes staged
-p, --patch Interactively select hunksCommon Use Cases
Quick Context Switch
# You're working on a feature, but need to fix a bug
$ dits status
Changes not staged for commit:
modified: src/feature.ts
# Stash your work
$ dits stash -m "WIP: new feature"
Saved working directory and index state "WIP: new feature"
# Now you have a clean working directory
$ dits checkout hotfix/urgent-bug
# ... fix the bug ...
$ dits commit -m "fix: urgent bug"
$ dits checkout feature/my-feature
# Restore your work
$ dits stash pop
On branch feature/my-feature
Changes not staged for commit:
modified: src/feature.ts
Dropped refs/stash@{0}Stash Specific Files
# Only stash certain files
$ dits stash push -m "WIP config" -- config/*.json
# Stash everything except staged changes
$ dits stash push --keep-indexView Stash Contents
# List all stashes
$ dits stash list
stash@{0}: WIP: new feature (2 hours ago)
stash@{1}: config changes (yesterday)
stash@{2}: experimental stuff (3 days ago)
# Show what's in a stash
$ dits stash show
src/feature.ts | 45 ++++++++++++++++++++++++++++++++++++-------
1 file changed, 38 insertions(+), 7 deletions(-)
# Show full diff
$ dits stash show -p
# Show specific stash
$ dits stash show stash@{1}Apply vs Pop
# Apply: restore changes but keep stash
$ dits stash apply
# Stash is still in the list
# Pop: restore changes and remove stash
$ dits stash pop
# Stash is removed from list
# Apply specific stash
$ dits stash apply stash@{2}
# Pop specific stash
$ dits stash pop stash@{1}Create Branch from Stash
# Create new branch and apply stash
$ dits stash branch new-feature stash@{0}
# This creates branch, checks it out, and applies stash
# Useful when stash conflicts with current branchManaging Stashes
# Delete a specific stash
$ dits stash drop stash@{2}
Dropped stash@{2}
# Delete all stashes (careful!)
$ dits stash clear
# Delete stashes older than 30 days
$ dits stash expire --older-than 30dRecover Dropped Stash
If you accidentally drop a stash, you can sometimes recover it:
dits fsck --unreachable | grep stashFind the hash and use dits stash apply <hash>Stash with Large Files
Dits handles large files efficiently in stashes. Unlike Git, stashing large binary files doesn't duplicate storage due to content addressing:
# Stash including large media files
$ dits stash -u -m "WIP with video changes"
Stashing video.mov (2.3 GB)...
Reusing 1,234 existing chunks
New chunks: 23 (45 MB)
Saved working directory and index stateRelated Commands
- checkout, switch - Change branches
- reset - Undo changes
- reflog - Recovery options