The two are entirely different commands:
git restore
is about copying some file(s) from somewhere to somewhere.
git rm
is about removing some file(s) from somewhere.
Because git restore
is about copying a file or files, it needs to know where to get the files. There are three possible sources:
- the current, or
HEAD
, commit (which must exist); or
- any arbitrary commit that you specify (which must exist); or
- Git's index aka staging area.
Because git rm
is about removing a file or files, it only needs to know the name(s) of the file(s) to remove. Adding --cached
tells git rm
to remove these files only from Git's index aka staging area.
On Pycharm, I can use git restore --staged to undo git add but on Visual Studio [I get the] error fatal: could not resolve HEAD
This error message indicates that you have no commits. That means there's no source from which to restore the file unless you choose the existing staging area as the source. So either there's a bug in VSCode (which is extremely likely1), or you have not yet made your first commit (which is even more likely). Your PyCharm IDE is probably able to do things because you have made your first commit by now.
This is also what your screenshots show.
1VSCode is ridiculously complicated and allows nearly arbitrary plug-in extensions, and judging by what I have seen here on SO, most of the extensions are positively riddled with bugs. That's not exactly VSCode's fault, but it's the kind of thing that would make me think again about using VSCode, if I could stand to use IDEs for any serious work in the first place.