GIT · Recovery · 5 min
Recover the deleted runbook
Restore one tracked file while preserving another unfinished edit.
Not completedYour task
Restore runbook.txt from the current commit. Keep the unfinished change in notes.txt. Do not stage or commit anything.
What you’re aiming for
- runbook.txt matches the committed version.
- notes.txt retains its draft edit.
- The staging area and commit history are unchanged.
1. Prepare your practice folder
Use Git 2.28 or newer. The setup commands below use a Bash-compatible shell: Git Bash on Windows, or Bash on Linux/macOS.
Create a new, empty folder for this exercise. If that name already exists, choose another new name. Continue only after you’re inside the new folder.
mkdir opsrung-git-restore-runbook && cd opsrung-git-restore-runbook
Run these setup commands in that folder:
git init --initial-branch=main git config --local user.name 'Practice Learner' git config --local user.email 'practice@example.invalid' printf 'Deploy:\n1. Run tests.\n2. Review rollout.\n' > runbook.txt printf 'Initial note.\n' > notes.txt git add . git commit -m 'Add runbook and notes' rm runbook.txt printf 'Keep this draft.\n' > notes.txt
Only if your personal Git settings interfere
You can normally skip this. If a commit asks for a signing key, runs a custom hook, or changes line endings unexpectedly, these repository-local overrides keep this disposable exercise independent of those settings.
git config --local commit.gpgsign false git config --local core.autocrlf false git config --local core.hooksPath .git/practice-no-hooks
Retry the failed command afterward. These settings apply only inside this practice repository.
2. Try the task
Work toward the goal above. Start by inspecting the files or resources, then use a hint if you need one.
Hint 1
Use git status to distinguish the deleted file from the edited note.
Hint 2
A repository-wide reset would affect work you need to keep.
Hint 3
Restore just runbook.txt from the index with git restore -- runbook.txt.
3. Review your result
Use these commands to look at your result and compare it with the goals. The website does not run or verify them.
cat runbook.txt git diff -- notes.txt git diff --staged git status
What you should see
- cat runbook.txt shows Deploy:, followed by 1. Run tests. and 2. Review rollout. on separate lines.
- git diff -- notes.txt still shows Keep this draft.
- git diff --staged produces no output. In git status, only the notes.txt edit remains.
If your result differs: Restore only runbook.txt. A repository-wide restore could erase the draft in notes.txt.
Compare with one possible solution
git restore -- runbook.txt
Other approaches are fine if you reach the same goal. Opening this solution does not mark the exercise complete.
Finished this exercise?
You decide when you’re done. Your choice is saved in this browser, and you can change it later.