Resetting Subdirectories in Git

How do you hard reset a subdirectory of a Git repository? Simple.

$ git checkout HEAD -- subdirectory

A word of warning. This replaces the working tree and the index with the HEAD commit.

Don't lose changes you might have already staged within the subdirectory. If this is the case and you wish to unstage those changes, use:

$ git reset -- subdirectory

Think of git reset -- path as the opposite of git add.

Moz Morris

Moz Morris

Freelance Web Developer