Restore one file from HEAD without touching the git index
@richardxu257▲ 1 net votes
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.