Retrieving Stashed Work
Listing Stashed Changes
Before retrieving stashed work, you'll want to view your available stashes:
git stash list
Example output:
stash@{0}: WIP on feature: 9f8d3a2 Implement login
stash@{1}: On main: database configuration changes
Applying Stashed Changes
Pop Stash
To apply and remove the most recent stash:
git stash pop
Apply Specific Stash
To apply a specific stash without removing it:
git stash apply stash@{1}
Stash Retrieval Strategies
Strategy |
Command |
Behavior |
Apply Latest |
git stash pop |
Applies and removes top stash |
Apply Specific |
git stash apply stash@{n} |
Applies stash without removing |
Selective Retrieval |
git stash show -p stash@{n} |
Shows patch of specific stash |
Workflow Visualization
graph TD
A[Stash List] -->|Select Stash| B[Working Directory]
B -->|git stash pop| C[Changes Applied]
B -->|git stash apply| D[Changes Copied]
Handling Conflicts
When applying stashed changes, potential merge conflicts may occur:
## If conflicts exist
git stash apply
## Resolve conflicts manually
git add .
git commit
Advanced Retrieval Techniques
Creating a Branch from Stash
git stash branch new-feature-branch stash@{0}
This command creates a new branch and applies the stashed changes.
Best Practices for LabEx Developers
- Always check stash list before applying
- Use descriptive stash messages
- Resolve conflicts carefully
- Clean up unnecessary stashes regularly
By mastering these retrieval techniques, developers can efficiently manage and restore their work across different development scenarios.