A developer is midway through an edit when an urgent request arrives. The branch must be clean for the switch, but the partial edits need to stay recoverable. Which action is correct?
Show answer and explanation
Answer: D
git stash records the working tree and index in a stash entry, leaving the branch clean for the switch. Reapplying with git stash pop, or git stash apply to keep the entry, restores the partial edits later. A placeholder commit pollutes history, a forced checkout discards local modifications, and deleting files loses the work entirely.
Why the other options are wrong
- A. A placeholder commit records unfinished work in shared history. It is harder to clean up than a stash entry and can be pushed by accident.
- B. A forced checkout overwrites local modifications. The partial edits would be lost, which is the opposite of what the developer wants.
- C. Deleting modified files destroys the partial edits. Recreating them later from memory is error-prone and wastes the work already done.