git reset --hard
expects a revision/commit, not a pathspec.
Resets the index and working tree. Any changes to tracked files in the working tree since commit are discarded. [emphasis mine]
If no revision is given, it defaults to HEAD
(the current commit)
In contrast git checkout
, when called as git checkout [tree-ish] -- pathspec...
, overwrites the files at the specified path(s) in the working directory and in the index with the content of the blob referenced from the given tree. If no tree is provided, i.e. git checkout -- pathspec...
, the files in the working directory are overwritten with the current content stored in the index
Overwrite the contents of the files that match the pathspec. When the tree-ish (most often a commit) is not given, overwrite working tree with the contents in the index. When the tree-ish is given, overwrite both the index and the working tree with the contents at the tree-ish. [emphasis mine]
To mimic the behavior of reset --hard
(without a revision), you can use git checkout HEAD -- pathspec...
.
Git 2.25 introduced git restore
. To get the same behavior with the new command, you'd use git restore --staged --worktree -- pathspec...
(or git restore -SW -- pathspec...
)