Loading lesson path
Concept visual
Formula
- Stash your changes git stash push - m "message"Formula
- List all stashes git stash branch < branchname >Sometimes you need to quickly switch tasks or fix a bug, but you're not ready to commit your work.
git stash lets you save your uncommitted changes and return to a clean working directory.You can come back and restore your changes later. Here are some common use cases:
Save your work before changing branches.
Stash your work to fix something urgent, then restore it.
Avoid messy commits or losing changes. Stash Your Changes ( git stash ) Save your current changes (both staged and unstaged tracked files) with:
(both staged and unstaged) are stashed by default.
(new files not yet added to Git) are not stashed by default.
Formula
To stash untracked files too, use git stash - u(or
Formula
-- include - untracked).
Saved working directory and index state WIP on main: 1234567 Add new feature This command saves your changes and cleans your working directory so you can safely switch tasks or branches. Your changes are now saved in a stack.
Each time you run git stash, your changes are saved on top of a "stack". The most recent stash is on top, and you can apply or drop stashes from the top down, or pick a specific one from the list. Your working directory is clean, and you can switch branches or pull updates safely. Stash with a Message (
Formula
git stash push - m) Add a message to remember what you stashed:
Example: Stash with a Message git stash push -m "WIP: homepage redesign" Saved working directory and index state On main: WIP: homepage redesign This command lets you add a descriptive message to your stash so you can remember what you were working on. List All Stashes ( git stash list )
Example: List Stashes git stash list stash@{0}: On main: WIP: homepage redesign stash@{1}: WIP on main: 1234567 Add new feature This command shows all the stashes you have saved so far, with their names and messages. Show Stash Details ( git stash show ) See what was changed in the latest stash:
Example: Show Latest Stash git stash show src/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) This command gives a summary of what files and changes are in your most recent stash.
Example: Show Full Diff git stash show -p diff --git a/src/index.html b/src/index.html index 1234567..89abcde 100644
Formula
--- a/src/index.html
+++ b/src/index.html@@ ... This command shows the exact lines that were changed in your most recent stash. Apply the Latest Stash ( git stash apply ) Restore your most recent stashed changes (keeps the stash in the stack):
Formula
(use "git add < file >..." to update what will be committed)
(use "git restore < file >..." to discard changes in working directory)
modified: src/index.htmlThis command restores your most recent stashed changes, but keeps the stash in the list so you can use it again if needed. Apply a Specific Stash (
git stash apply stash@{n}) Restore a specific stash from the list:
Example: Apply a Specific Stash git stash apply stash@{1}
Formula
modified: src/index.htmlThis command lets you restore a specific stash from your list, not just the most recent one. Pop the Stash ( git stash pop ) Apply the latest stash and remove it from the stack
Formula
modified: src/index.htmlDropped refs/stash@{0} (abc1234d5678)This command restores your most recent stash and removes it from the list at the same time. Drop a Stash ( git stash drop ) Delete a specific stash when you no longer need it:
Example: Drop a Stash git stash drop stash@{0}
Dropped stash@{0} (abc1234d5678)This command deletes a specific stash from your list when you no longer need it. Clear All Stashes ( git stash clear ) Delete all your stashes at once:
This command deletes all your stashes at once. Be careful! This cannot be undone! Branch from a Stash ( git stash branch ) Create a new branch and apply a stash to it. Useful if your stashed work should become its own feature branch:
Example: Branch from a Stash git stash branch new-feature stash@{0}
Formula
modified: src/index.htmlDropped stash@{0} (abc1234d5678)This command creates a new branch and applies your stashed changes to it. This is useful if you decide your work should become its own feature branch.