0
0
Gitdevops~20 mins

Stashing specific files in Git - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Stash Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of stashing only a specific file?
You have modified two files: file1.txt and file2.txt. You run the command git stash push file1.txt. What will be the state of the working directory after this command?
Afile1.txt is reverted to the last commit state; file2.txt remains modified.
BBoth file1.txt and file2.txt are reverted to the last commit state.
COnly file2.txt is reverted to the last commit state; file1.txt remains modified.
DNo files are reverted; the stash command fails with an error.
Attempts:
2 left
💡 Hint
Think about how specifying a file affects what is stashed and what remains.
🧠 Conceptual
intermediate
1:30remaining
Which command stashes changes only from a specific file?
You want to stash changes only from app.js without affecting other files. Which git command achieves this?
Agit stash save app.js
Bgit stash push app.js
Cgit stash app.js
Dgit stash --only app.js
Attempts:
2 left
💡 Hint
Look for the modern syntax to stash specific files.
Troubleshoot
advanced
2:30remaining
Why does git stash push file.txt stash all changes instead of just file.txt?
You ran git stash push file.txt expecting only file.txt to be stashed. But all modified files were stashed. What is the most likely reason?
AYou have unstaged changes in other files; <code>git stash push</code> stashes all unstaged changes by default.
BYou ran the command in a subdirectory; file paths must be relative to the repository root.
CYou used an older Git version that does not support specifying files with <code>git stash push</code>.
DThe file name was misspelled, so Git ignored it and stashed everything.
Attempts:
2 left
💡 Hint
Check your Git version and feature support.
🔀 Workflow
advanced
2:00remaining
What is the correct workflow to stash changes from only index.html and keep other changes intact?
You have changes in index.html and style.css. You want to stash only index.html changes and keep style.css changes in your working directory. Which sequence of commands achieves this?
Agit stash push index.html
Bgit add index.html && git stash push --keep-index
Cgit stash push -- path/to/index.html
Dgit stash save index.html
Attempts:
2 left
💡 Hint
Consider the simplest way to stash only one file's changes.
Best Practice
expert
3:00remaining
What is the best practice to stash only part of the changes in a file?
You modified app.py but want to stash only some of the changes, not the entire file. Which approach is best?
ASplit the file into two files and stash one of them.
BRun <code>git stash push app.py</code> and manually edit the stash later.
CUse <code>git stash push --patch app.py</code> to interactively select changes.
DUse <code>git add -p app.py</code> to stage parts, then run <code>git stash push --keep-index</code>.
Attempts:
2 left
💡 Hint
Think about staging parts of files before stashing.