microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
164.96k stars 29.53k forks source link

Command for `git restore` #177569

Open garretwilson opened 1 year ago

garretwilson commented 1 year ago

There needs to be a command "Git: Restore" which would discard local changes to the file, as if I would have entered git restore … in the terminal.

As an example of other commands, there already exists a command "Git: Stage Changes" which stages the changes for the current file, as if I would have entered git add … in the terminal.

"Git: Restore" is a very commonly needed command, but it seems to be missing.

See:

chloezulcosky commented 1 year ago

@sofiabe1 and I plan to look into this

deitry commented 1 year ago

Also it seems that "discard changes" button in Source Control view calls git checkout -q -- <file> command, and can be replaced with git restore

iifawzi commented 1 year ago

Hi, I'd love to work on this, but if git checkout is covering all the cases when it comes to discard changes? what would git restore add then?

garretwilson commented 1 year ago

Hi, I'd love to work on this, but if git checkout is covering all the cases when it comes to discard changes?

First, did you read the links in the description? They explain it in depth.

Secondly, when I hit Ctrl+Shift+P, I don't see an option for a per-file git checkout, either. But as pointed out several times in the Stack Overflow question/answer:

… git-restore seems the safer option if you only want to revert local work.

But don't take my word for it. Read all the history and technical details in the link.