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 your 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 you no longer need:

git stash drop stash@{INDEX}

Diff Patches: Named, Reusable Change Sets

Diff patches allow you to save changes 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


Summary