Git Reset Paths: Change the Index Without Moving HEAD
Two forms of reset
Commit-level reset moves HEAD, but git reset REV -- path copies selected entries from a tree into the index. It does not update the working file or branch tip. The separator -- tells Git the remaining arguments are paths. The source defaults to HEAD. Use the paths scenario, with two staged files and an additional unstaged edit to notes.txt.
Unstage only the chosen file
Initially notes.txt has B in HEAD, C in the index and D in the working file; light.txt has Base light in HEAD and New light in both other layers. After resetting notes.txt from HEAD, its index becomes B, its working file stays D, and light.txt is still staged. The index version C is no longer staged; if C matters independently of D, save it before resetting.
git reset HEAD -- notes.txtgit show :notes.txtcat notes.txtgit diff --cached --name-onlygit rev-parse HEADChoose a different source tree
The target may be a historical commit rather than HEAD. In this example HEAD^ contains A, so the next command stages A, even though HEAD contains B and the working file contains D. It is not necessarily an unstage operation. Restore with --staged is a clearer equivalent when the goal is index-only restoration; specify --source explicitly. A newly added file absent from the source becomes untracked if its working copy remains.
git reset HEAD^ -- notes.txtgit show :notes.txtgit diff --cached -- notes.txtgit restore --staged --source=HEAD -- notes.txtPrefer the smallest operation
Path reset can change the next commit but never rewrites the current commit. Reset -p interactively reverses selected index hunks relative to a source; it is an optional concept, not part of this fixture. For a shared committed mistake, use revert when suitable rather than reset. For viewing old content without changes, use git show. Practice: stage new.txt, reset that path from HEAD and check that it is untracked and still present.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Git Reset Paths: Change the Index Without Moving HEAD — knowledge check
Reason about reset states and safe recovery.
What does git reset HEAD -- notes.txt change?
What if the source tree contains A but HEAD contains B?
What happens to other staged files?
A newly staged file is absent from HEAD. What does resetting that path do?
Which alternative explicitly targets only the index?