Git Stash and Diff Patches
Saving Changes to Apply Later in Git
Git provides lightweight ways to save uncommitted changes so they can be applied later—useful for repeated deployment tweaks, build configuration changes, or quick context switching without commits.
Git Stash: Temporary Change Storage
Git stash temporarily saves the working directory changes and restores a clean state.
Basic Stash Operations
List all saved stashes:
git stash list
Save current changes with an automatic message:
git stash
Save current changes with a custom description:
git stash push -m "description"
Apply the most recent stash without removing it:
git stash apply
Apply a specific stash by index:
git stash apply stash@{INDEX}
Apply and remove the most recent stash:
git stash pop
Remove a stash that is no longer needed:
git stash drop stash@{INDEX}
Diff Patches: Named, Reusable Change Sets
Diff patches allow changes to be saved as files, making them easy to name, reuse, and apply across branches or repositories.
Save the current working changes into a reusable patch file:
git diff > changes.save
Re-apply the saved changes at any time:
git apply changes.save
When to Use Each Approach
- Use stash for quick, short-term saves while switching tasks or branches
- Use diff patches for named, repeatable changes that need to be applied on demand
Summary
- Git stash is ideal for temporary local saves
- Diff patches are best for persistent, reusable change sets
- Both help save changes without committing, keeping history clean