0
0
Gitdevops~10 mins

Stashing specific files in Git - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Stashing specific files
Modify files in working directory
Select specific files to stash
Run git stash push -m "msg" -- <files>
Git saves changes of selected files
Working directory: selected files reverted, others unchanged
Later: git stash list to see stash
Apply or drop stash as needed
This flow shows how to stash changes from only certain files, leaving others untouched, then manage the stash later.
Execution Sample
Git
git stash push -m "Save changes to file1 only" -- file1.txt
# Stashes changes only in file1.txt, not others
This command saves changes from file1.txt into a stash, leaving other files' changes in place.
Process Table
StepCommand/ActionFiles ChangedStash ContentWorking Directory State
1Modify file1.txt and file2.txtfile1.txt, file2.txtNonefile1.txt and file2.txt modified
2git stash push -m "Save file1" -- file1.txtfile1.txt, file2.txtfile1.txt changes savedfile1.txt reverted, file2.txt still modified
3git stash listNonestash@{0}: Save file1file1.txt reverted, file2.txt still modified
4git stash apply stash@{0}file1.txt, file2.txtstash@{0}: Save file1file1.txt and file2.txt modified
5git stash drop stash@{0}NoneNonefile1.txt and file2.txt modified
💡 After stashing specific files, only those files revert; stash can be applied or dropped later.
Status Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4After Step 5
file1.txtcleanmodifiedclean (stashed)clean (stashed)modified (restored)modified
file2.txtcleanmodifiedmodified (unchanged)modified (unchanged)modified (unchanged)modified
stash listemptyemptystash@{0}: Save file1stash@{0}: Save file1stash@{0}: Save file1empty
Key Moments - 3 Insights
Why does file2.txt remain modified after stashing file1.txt?
Because the stash command included only file1.txt, git saved and reverted changes only for that file, leaving file2.txt untouched as shown in step 2 of the execution_table.
What happens if you run 'git stash apply' after stashing specific files?
The stashed changes for the selected files are reapplied to the working directory, restoring their modified state as seen in step 4.
Does the stash disappear immediately after pushing changes?
No, the stash remains in the stash list until explicitly dropped, visible in step 3 and removed in step 5.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 2: What is the state of file1.txt after stashing?
ADeleted
BModified
CClean (reverted)
DUntracked
💡 Hint
Check the 'Working Directory State' column at step 2 in the execution_table.
At which step does the stash list show the saved stash?
AStep 1
BStep 3
CStep 2
DStep 5
💡 Hint
Look at the 'stash list' variable in variable_tracker and the 'Stash Content' column in execution_table.
If you stash both file1.txt and file2.txt, how would the working directory state change after stashing?
ABoth files revert to clean
BBoth files remain modified
COnly file1.txt reverts, file2.txt stays modified
DOnly file2.txt reverts, file1.txt stays modified
💡 Hint
Refer to the behavior shown in step 2 where only selected files revert after stashing.
Concept Snapshot
git stash push -m "message" -- <files>
- Saves changes only from specified files
- Reverts those files in working directory
- Other files remain unchanged
- Use git stash list to see saved stashes
- Apply or drop stash later as needed
Full Transcript
This visual execution shows how to stash changes from specific files using git. First, you modify multiple files. Then you run 'git stash push' with the file names to stash only those files. Git saves changes from those files and reverts them in your working directory, while other files stay modified. The stash is listed with 'git stash list'. Later, you can apply the stash to restore changes or drop it to remove. This helps manage partial changes safely.