Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can one discard individual changes in a file in Visual Studio Code?

In Visual Studio Code, you can rollback all the changes to a file:

enter image description here

But is it possible if you have multiple changes in a file on multiple line numbers, to rollback only one of them, as one can in PhpStorm?

like image 670
Edward Tanguay Avatar asked Aug 24 '17 09:08

Edward Tanguay


People also ask

How do you discard changes in VS code?

There could be a set of changed files, which you don't want to commit and want to undo the changes that you have already performed. Select those files/folders and right click on them to open the Git context menu, where you can click Undo Changes... to discard them.

How do I revert changes in Visual Studio code?

Click the (...) button and then select Undo Last Commit to undo the previous commit. The changes are added to the Staged Changes section.

How do I get rid of changes in Visual Studio?

If the file is in the Changes section, right-click it and choose Undo Changes to discard all changes to the file since the last commit. Visual Studio supports discarding all uncommitted changes to a file by reverting the file to its version in the last commit.

How do you delete multiple items in VScode?

“vs code delete multiple lines” Code Answer'sWindows: Ctrl + Alt + Arrow Keys. Linux: Shift + Alt + Arrow Keys. Mac: Opt + Cmd + Arrow Keys.


2 Answers

Update: in the October 2017 release, "inline change review" was introduced, where you can easily discard a particular change in the same way as you would in IntelliJ-based IDEs:


Previously, this was only possible with the Open Changes UI (located in the upper right of editors ). Alternatively, you can run the Git: Open Changes command.

In that view, the More button () offers several options for operating on individual lines, among them Revert Selected Ranges.

like image 79
Gama11 Avatar answered Sep 20 '22 13:09

Gama11


There is Revert Selected Changes. Either hit Ctrl+Shift+P on the diff viewer to revert selected or simply use Ctrl+K,R

enter image description here

like image 35
Amit Avatar answered Sep 22 '22 13:09

Amit