Bird
Raised Fist0
Gitdevops~20 mins

git stash apply vs pop - Practice Questions

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Git Stash Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Difference between git stash apply and git stash pop

Which statement correctly describes the difference between git stash apply and git stash pop?

A<code>git stash apply</code> creates a new stash; <code>git stash pop</code> only shows the stash contents.
B<code>git stash apply</code> reapplies the stash but keeps it in the stash list; <code>git stash pop</code> reapplies and removes the stash from the list.
C<code>git stash apply</code> deletes the stash without applying it; <code>git stash pop</code> applies the stash but keeps it in the list.
D<code>git stash apply</code> permanently deletes all stashes; <code>git stash pop</code> restores the last commit.
Attempts:
2 left
💡 Hint

Think about whether the stash remains after applying it.

💻 Command Output
intermediate
1:30remaining
Output after using git stash pop

You have one stash saved. You run git stash pop. What happens to the stash list?

AThe stash is reapplied and removed from the stash list, leaving the list empty.
BThe stash is reapplied but remains in the stash list.
CThe stash list is cleared without applying any changes.
DAn error occurs because <code>git stash pop</code> cannot be used with one stash.
Attempts:
2 left
💡 Hint

Remember what pop means in everyday life: to take something out.

Troubleshoot
advanced
2:00remaining
Resolving conflicts after git stash pop

You run git stash pop and get a conflict error. What is the best next step?

ARun <code>git stash apply</code> again to fix the conflicts automatically.
BRun <code>git reset --hard</code> to discard all changes and conflicts.
CManually resolve the conflicts in the files, then run <code>git add</code> and <code>git commit</code>.
DRun <code>git stash drop</code> to remove the stash and ignore the conflicts.
Attempts:
2 left
💡 Hint

Conflicts need manual attention before continuing.

🔀 Workflow
advanced
1:30remaining
Choosing between git stash apply and git stash pop in a workflow

You want to test changes saved in a stash but keep the stash for later use if needed. Which command should you use?

AUse <code>git stash apply</code> to reapply changes without removing the stash.
BUse <code>git stash pop</code> to reapply and remove the stash immediately.
CUse <code>git stash drop</code> to remove the stash without applying it.
DUse <code>git stash clear</code> to remove all stashes before applying.
Attempts:
2 left
💡 Hint

Think about whether you want to keep the stash after testing.

Best Practice
expert
2:30remaining
Best practice to avoid losing stashed changes accidentally

Which practice helps avoid losing stashed changes when using git stash pop?

AUse <code>git stash clear</code> regularly to keep the stash list clean.
BAlways use <code>git stash pop</code> directly to save time and avoid extra commands.
CNever use stashes; commit all changes immediately to avoid confusion.
DUse <code>git stash apply</code> first to test changes, then <code>git stash drop</code> after confirming success.
Attempts:
2 left
💡 Hint

Think about how to keep a backup until you are sure changes are good.

Practice

(1/5)
1. What is the main difference between git stash apply and git stash pop?
easy
A. git stash apply only shows the stash content, git stash pop applies it.
B. git stash apply deletes the stash after applying, git stash pop keeps it.
C. git stash apply restores changes but keeps the stash saved, while git stash pop restores changes and removes the stash.
D. git stash apply creates a new stash, git stash pop deletes all stashes.

Solution

  1. Step 1: Understand git stash apply behavior

    This command restores the saved changes from the stash but keeps the stash entry intact for future use.
  2. Step 2: Understand git stash pop behavior

    This command restores the changes and then removes the stash entry, cleaning up automatically.
  3. Final Answer:

    git stash apply restores changes but keeps the stash saved, while git stash pop restores changes and removes the stash. -> Option C
  4. Quick Check:

    Apply keeps stash, pop removes stash [OK]
Hint: Apply keeps stash, pop removes stash after applying [OK]
Common Mistakes:
  • Thinking apply deletes stash
  • Confusing pop with apply
  • Believing apply only previews changes
  • Assuming pop keeps stash
2. Which of the following is the correct syntax to restore stash changes and remove the stash entry?
easy
A. git stash apply
B. git stash pop
C. git stash save
D. git stash list

Solution

  1. Step 1: Identify command to restore and remove stash

    git stash pop restores the changes and deletes the stash entry.
  2. Step 2: Confirm other commands

    git stash apply restores but keeps stash; git stash save creates stash; git stash list shows stashes.
  3. Final Answer:

    git stash pop -> Option B
  4. Quick Check:

    Pop restores and removes stash [OK]
Hint: Pop restores and deletes stash, apply keeps stash [OK]
Common Mistakes:
  • Using apply instead of pop to remove stash
  • Confusing save with pop
  • Trying to remove stash with list
  • Using wrong command syntax
3. Given this sequence of commands:
git stash save "work in progress"
git stash apply
What happens to the stash list after these commands?
medium
A. The stash list still contains the saved stash.
B. The stash list is empty.
C. The stash list contains two identical stashes.
D. The stash list is deleted.

Solution

  1. Step 1: Save a stash

    git stash save "work in progress" creates a stash entry and saves changes.
  2. Step 2: Apply stash without removing

    git stash apply restores changes but keeps the stash entry intact.
  3. Final Answer:

    The stash list still contains the saved stash. -> Option A
  4. Quick Check:

    Apply keeps stash in list [OK]
Hint: Apply restores but stash remains in list [OK]
Common Mistakes:
  • Assuming apply removes stash
  • Thinking stash list duplicates
  • Believing stash list clears automatically
  • Confusing apply with pop
4. You ran git stash pop but got a conflict error. What should you do to fix this?
medium
A. Run git stash apply again to fix conflicts automatically.
B. Run git stash pop again without resolving conflicts.
C. Delete the stash file manually from .git folder.
D. Manually resolve conflicts, then run git stash drop to remove stash.

Solution

  1. Step 1: Understand conflict on pop

    git stash pop applies changes and removes stash, but conflicts can occur if changes clash.
  2. Step 2: Resolve conflicts and clean stash

    Manually fix conflicts, then remove stash with git stash drop if pop did not remove it due to conflict.
  3. Final Answer:

    Manually resolve conflicts, then run git stash drop to remove stash. -> Option D
  4. Quick Check:

    Fix conflicts, then drop stash manually [OK]
Hint: Resolve conflicts manually, then drop stash [OK]
Common Mistakes:
  • Rerunning pop without fixing conflicts
  • Assuming apply fixes conflicts automatically
  • Deleting stash files manually
  • Ignoring conflicts and continuing
5. You want to test changes saved in a stash without removing it, then later clean up if everything works. Which sequence of commands should you use?
hard
A. git stash apply; if okay, git stash drop
B. git stash pop; if okay, git stash apply
C. git stash drop; then git stash apply
D. git stash list; git stash pop

Solution

  1. Step 1: Use git stash apply to test changes

    This command restores changes but keeps stash, so you can test without losing the stash.
  2. Step 2: Remove stash if tests pass

    If changes work well, run git stash drop to delete the stash and clean up.
  3. Final Answer:

    git stash apply; if okay, git stash drop -> Option A
  4. Quick Check:

    Apply to test, drop to clean [OK]
Hint: Apply to test, drop to remove stash later [OK]
Common Mistakes:
  • Using pop first and losing stash before testing
  • Dropping stash before applying
  • Applying stash twice unnecessarily
  • Confusing list with apply or pop