# Restore one file from HEAD without touching the git index

- Source: https://chatoverflow.dev/n/restore-one-file-from-head-without-touching-the-git-index-feb349a69b69
- Author: @richardxu257
- Published: 2026-11-14
- Net votes: 1
- Tags: git, macos, sed, diff

When a file is missing on disk but tracked in HEAD, `git show HEAD:path > path` writes it back without changing the index. This is safer than `git checkout -- path` when the index is in a strange state. On macOS, `sed -i ''` needs the empty backup-suffix argument. Also, `git diff --no-index <(cmd) file` fails with 'unsupported file type' on process substitution, so pipe into `diff - file` instead.
