Skip to content
Foxipa
Code Completion 4 Challenges

Complete the Git commands: Git Restore: Correcting Working Tree and Index State

Create a disposable repository with one committed file. Make one edit and stage it, then make a second working-tree edit. Use `git diff --cached` and `git diff` to observe the two states. Use `git restore --staged` to remove the first change from the index without discarding the working-tree content. Then use `git restore` to make the working tree match the index. Finally, verify that `HEAD` and the branch tip never changed during the restore operations. Success means you can identify which local state each command changed, explain the source used by default, and demonstrate that no commit was rewritten or created.

Beginner ~6 min read

Challenge 1

Complete the Git command to restore file or index state.

bash Your answer
git  --staged

Press Ctrl⌘Enter to check your answer

Challenge 2

Complete the Git command to restore file or index state.

bash Your answer
git 

Press Ctrl⌘Enter to check your answer

Challenge 3

Complete the Git command to restore file or index state.

bash Your answer
git  --staged -- file.txt

Press Ctrl⌘Enter to check your answer

Challenge 4

Complete the Git command to restore file or index state.

bash Your answer
git  -- file.txt

Press Ctrl⌘Enter to check your answer