QuestenaPractice that shows what to review next
Question 11

You edited the tracked file notes.md and staged the change with `git add`, but now want to unstage it while keeping your edits in the working tree. Which command does exactly that?

  1. git checkout -- notes.md
  2. git restore --staged notes.mdCorrect answer
  3. git rm --cached notes.md
  4. git stash push notes.md

Explanation

`git restore --staged` resets the file's index entry back to the HEAD version, unstaging the change while leaving the working tree untouched — exactly what was asked. `git checkout -- notes.md` restores the working-tree file from the index, not from HEAD — here your edit is already staged, so it would change nothing and unstage nothing. `git rm --cached` removes the file from the index entirely, staging a deletion of a tracked file. `git stash push` takes the changes out of your working tree as well, which violates the 'keep my edits' requirement.

Continue with this test

Start practice
Question 11: You edited the tracked file notes.md and staged the change… · Git Fundamentals · Questena