# M02-L05 — Challenge: save only what belongs

**Outcome:** Exclude harmless generated output while preserving and committing the intended change.

**Start:** M02-L01–04; disposable CP01 practice repository with an existing baseline.

This challenge checks whether you can use repository state to choose a precise recovery. The starting repository already has a baseline commit. It contains a useful README edit and a harmless generated teaching file named `build-note.tmp`. Both have been staged deliberately. The task is to keep the useful edit and exclude the temporary file without deleting useful work.

Inspect `git status`, `git diff`, and `git diff --cached` before changing state. Read the content of the teaching temporary file so you know what it is. This exercise never uses credentials or private data. The unwanted path is newly staged after an existing commit, which makes the recovery context explicit.

Use `git restore --staged -- build-note.tmp` to remove that path from the next commit while keeping the working file. Add the exact ignore entry for this teaching artifact, inspect `.gitignore`, and stage only the intended README and ignore change. Ignore patterns affect matching untracked paths; they do not erase previously committed history. [git restore](https://git-scm.com/docs/git-restore), [gitignore](https://git-scm.com/docs/gitignore)

Review the final cached diff before committing. The temporary file must be absent, the useful README edit must remain, and the ignore rule must be suitably narrow. An empty diff achieved by discarding everything would fail the task because it loses the intended improvement.

Finish with a review note explaining the starting state, what you preserved, what changed in staging, and what entered history. Complete Q02. Your observable evidence is the actual selected snapshot and final file state, not merely a checked progress box.

## Practice and completion

Complete the [exercise](exercise.md), then compare your artifact with the separately distributed instructor answer. A lesson acknowledgment records your own progress; it does not certify that a physical test occurred.

## Reading and figures

[Chapter 4](../../../../book/chapters/ch04/chapter.md), [Chapter 5](../../../../book/chapters/ch05/chapter.md). Resources: [Project checkpoint guide](../../../../examples/sensor-monitor/docs/checkpoints.md) and [toolchain setup](../../../../examples/sensor-monitor/docs/setup.md). Figure references: SS05-02 and D05. SS05-02 shows the earlier baseline selection, with source files staged and generated `build/` output ignored. It illustrates the distinction between source and generated output. It does not show this challenge’s temporary-file recovery; the lesson recording shows the actual `build-note.tmp` creation, unstage, ignore-rule edit, final commit and saved review note.
