First, 'Hello' is written to file.txt. Then, git add stages it. Next, git restore --staged file.txt removes it from staging but keeps the change.
Step 2: Understand the status after unstaging
Since the file is modified but unstaged, git status will show it as modified but not staged for commit.
Final Answer:
file.txt is modified but not staged. -> Option D
Quick Check:
Unstaged changes = modified but not staged [OK]
Hint: Unstaged files show as modified but not staged [OK]
Common Mistakes:
Assuming file is still staged after restore --staged
Thinking file is unmodified after unstaging
Confusing unstaged with deleted
4. You ran git restore --staged myfile.txt but got an error: error: pathspec 'myfile.txt' did not match any files. What is the most likely cause?
medium
A. The file myfile.txt is not currently staged.
B. You misspelled the command; it should be git reset --staged.
C. The file does not exist in the working directory.
D. You need to add --force to the command.
Solution
Step 1: Understand the error message meaning
The error says the file path does not match any staged files, meaning Git can't find it in the staging area.
Step 2: Check the file's staging status
If the file is not staged, git restore --staged cannot unstage it, causing this error.
Final Answer:
The file myfile.txt is not currently staged. -> Option A
Quick Check:
Unstage error means file not staged [OK]
Hint: File must be staged to unstage it [OK]
Common Mistakes:
Assuming command syntax is wrong
Thinking file must exist only in working directory
Trying to force unstage without staging first
5. You staged two files, index.html and style.css, but realize you only want to commit index.html. Which command correctly unstages style.css without losing your edits?
hard
A. git checkout -- style.css
B. git restore --staged style.css
C. git reset --hard style.css
D. git rm --cached style.css
Solution
Step 1: Identify the goal
You want to unstage style.css but keep your changes in the working directory.
Step 2: Compare commands
git restore --staged style.css unstages the file but keeps edits. git reset --hard style.css is invalid syntax with paths and cannot unstage a specific file. git checkout -- style.css updates working tree from index but does not unstage. git rm --cached style.css stages a deletion, which is not desired.
Final Answer:
git restore --staged style.css -> Option B
Quick Check:
Use restore --staged to unstage safely [OK]
Hint: Use git restore --staged to unstage without losing edits [OK]