Stash Workflow Techniques
Advanced Stash Management
Selective Stashing
Git allows you to stash specific files or parts of your changes:
## Stash only specific files
git stash push -- file1.txt file2.py
## Interactive stash (stage changes first)
git add -p
git stash
Stash with Untracked Files
## Include untracked files in stash
git stash save -u "Stash with untracked files"
## Include all files, including ignored files
git stash save -a "Comprehensive stash"
Stash Manipulation Techniques
Managing Multiple Stashes
graph TD
A[Multiple Stashes] --> B[Identify Stash Index]
B --> C[Apply Specific Stash]
C --> D[Remove Unwanted Stashes]
Applying Specific Stashes
## List stashes with index
git stash list
## Apply a specific stash
git stash apply stash@{2}
## Apply and remove a specific stash
git stash pop stash@{1}
Stash Comparison and Inspection
Command |
Purpose |
Usage |
git stash show |
View stash changes |
Inspect stashed modifications |
git stash show -p |
Show full diff |
Detailed stash content |
git stash branch |
Create branch from stash |
Preserve stashed work |
Advanced Workflow Scenarios
Creating a Branch from Stash
## Create a new branch from a stash
git stash branch new-feature-branch stash@{0}
Cleaning Up Stashes
## Remove a specific stash
git stash drop stash@{1}
## Clear all stashes
git stash clear
Conflict Handling
Stash Conflict Resolution
## Apply stash and handle conflicts manually
git stash apply
## If conflicts occur
## 1. Resolve conflicts in files
## 2. Stage resolved files
git add .
git stash drop
LabEx Workflow Recommendation
At LabEx, we suggest developing a systematic approach to stashing:
- Use descriptive stash messages
- Regularly review and clean up stashes
- Leverage stash for seamless context switching
Pro Tips
- Use
git stash save
with meaningful messages
- Combine stashing with branching for complex workflows
- Always verify stash contents before applying