$ git reset -- can reset by path.
However, $ git reset (--hard|--soft) will report an error like below:
The git reset manual lists 3 ways of invocation:
2 are file-wise: These do not affect the working tree, but operate only on the files in the index specified by :
git reset [-q] [] [--] .. git reset (--patch | -p) [] [--] [...] 1 is commit-wise: Operates on all files in the referenced , and may affect the working tree:
git reset [] [] There's no mode of invocation that operates only on specified files and affects the working tree.
If you want to both:
You can use this alias in your git config file:
[alias]
reco = !"cd \"${GIT_PREFIX:-.}\" && git reset \"$@\" && git checkout \"$@\" && git status --short #" # Avoid: "fatal: Cannot do hard reset with paths."
You can then do one of:
$ git reco
$ git reco
$ git reco --
(Mnenonic for reco: reset && checkout)