Git Reset, Revert, and Restore Cheat Sheet/Interactively restore hunks

Select portions of a file to restore interactively.

Section: Restore Basics

Interactively restore hunks

bash
bash
git restore --patch path/to/file
Explanation

Powerful for partial undo operations at hunk granularity.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Restore Basics
Discard unstaged changes in a file
Restore a file in the working tree from the index.
OpenIn sheetbashsame section
Unstage a file with restore
Restore the index entry for a path from HEAD.
OpenIn sheetbashsame section
Restore a file from another commit
Copy file contents from a specific commit into the working tree.
OpenIn sheetbashsame section
Restore both index and working tree from another commit
Reset a file to another revision in both staging area and working tree.
OpenIn sheetbashsame section
Mental model for reset vs restore vs revert
Quick decision guide for the three similarly named commands.
OpenIn sheettext2 tag match
Undo last commit but keep everything staged
Move HEAD back one commit while preserving index and working tree.
OpenIn sheetbash1 tag match