git reset -- <path>
This command is useful when you accidentally add files to the index and want to remove them from the next commit without losing the actual changes in your working directory.
This command runs git reset in its default --mixed mode but limits the operation to the specified <path>, and the -- is used to clearly separate options from paths so that git treats everything after it as a file or directory path, even if it looks like a flag. By doing this, it updates the index (staging area) for <path> to match HEAD (the last commit), effectively unstaging those changes while leaving your modified files on disk untouched. The <path> can be a single file like <path> = src/app.js, a directory like <path> = src/, or even a glob-like path pattern depending on your shell (for example, src/*.js).
You can apply the same idea to multiple files at once, for example using git reset -- file1.txt dir/file2.js, or unstage everything with git reset or git reset -- . (note that omitting the path affects all tracked files). To completely discard local changes for a specific file (both staged and unstaged), you would instead use git restore <path> or older-style git checkout -- <path>, which reset the working copy too; to undo a commit but keep changes staged you might use git reset --soft <commit>, and to move the branch pointer and unstage changes for the whole tree you can use git reset --mixed <commit> (default) or git reset --hard <commit> if you want to discard them entirely.
Examples:
git reset -- src/app.jsgit reset -- src/