0
0
Gitdevops~10 mins

git stash to save changes - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - git stash to save changes
Make changes in files
Run 'git stash'
Changes saved in stash
Working directory clean
Later: Run 'git stash apply' or 'git stash pop'
Changes restored to working directory
You save your current changes safely with 'git stash', clean your workspace, and later restore those changes when ready.
Execution Sample
Git
git stash
# saves changes and cleans working directory

git stash list
# shows saved stashes

git stash apply
# reapplies last stash
This sequence saves your current changes, lists saved stashes, and reapplies the last saved changes.
Process Table
StepCommandActionResultWorking Directory State
1Modify files (e.g., edit file.txt)Change detectedFiles modified but not committedUncommitted changes present
2git stashSave changes to stashChanges saved, working directory cleanedNo uncommitted changes
3git stash listShow stash entriesOne stash entry listedWorking directory clean
4git stash applyReapply last stashChanges restored to filesUncommitted changes present
5git stash dropRemove stash entryStash entry deletedUncommitted changes remain
6git stash popReapply and drop stashChanges restored and stash removedUncommitted changes present
7git stash listShow stash entriesNo stash entriesWorking directory state unchanged
8-No more stashesNo actionWorking directory state unchanged
💡 No more stash entries to apply or list
Status Tracker
VariableStartAfter Step 1After Step 2After Step 4After Step 6Final
Working DirectoryCleanModified files presentClean (changes stashed)Modified files restoredModified files restoredModified files restored
Stash ListEmptyEmptyOne stash entryOne stash entryEmpty (after pop)Empty
Key Moments - 3 Insights
Why does 'git stash' make my working directory clean?
'git stash' saves your changes safely and removes them from the working directory, so it looks clean as shown in step 2 of the execution_table.
What is the difference between 'git stash apply' and 'git stash pop'?
'git stash apply' restores changes but keeps the stash entry (step 4), while 'git stash pop' restores changes and deletes the stash entry (step 6).
Why might I see no stash entries after 'git stash pop'?
Because 'git stash pop' reapplies and removes the stash entry, leaving the stash list empty as shown in step 7.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 2. What is the state of the working directory after running 'git stash'?
AIt is clean with no uncommitted changes
BIt still has uncommitted changes
CIt has committed changes only
DIt is deleted
💡 Hint
Check the 'Working Directory State' column at step 2 in the execution_table
At which step does the stash list become empty again after having entries?
AStep 4
BStep 5
CStep 7
DStep 6
💡 Hint
Look at the 'Stash List' variable in variable_tracker and the 'Result' column in execution_table
If you want to restore changes but keep the stash for later, which command should you use?
Agit stash pop
Bgit stash apply
Cgit stash drop
Dgit stash list
💡 Hint
Refer to the difference explained in key_moments between 'apply' and 'pop'
Concept Snapshot
git stash saves your current uncommitted changes safely.
It cleans your working directory so you can work on something else.
Use 'git stash apply' to restore changes without deleting stash.
Use 'git stash pop' to restore and delete stash entry.
Check saved stashes with 'git stash list'.
Full Transcript
This visual execution shows how 'git stash' saves your current changes and cleans your working directory. You start by modifying files, then run 'git stash' to save those changes safely. The working directory becomes clean, allowing you to switch tasks. Later, you can use 'git stash apply' to restore changes without removing the stash, or 'git stash pop' to restore and delete the stash entry. The stash list shows saved entries and updates as you apply or drop stashes. This helps keep your work safe and organized.