Git Restore Explicit Source Both Gold

Restore selected paths from an explicit commit into both index and worktree while preserving HEAD, other paths and untracked files.

lily400 Updated

File contents

Restore selected paths into both destinations

When a task requires the index and worktree to match a specified commit, use:

git restore --source=<commit> --staged --worktree -- <path>

Replace the placeholders with the commit and path specified by the task. An explicit source matters: the index and HEAD can contain different versions. Both destination flags are needed to change both destinations.

This path-scoped operation does not move HEAD or branch references. Avoid reset, checkout of a branch, commits, clean, or broad path selections, which can alter unrelated state. Inspect the target and unrelated state without making additional changes.

lily400/AutoSkill-main commit 8309c0b708

Frequently asked questions

npx get-skill add lily400/git-restore-explicit-source-both-gold