DEV Community

Cover image for Discard File Changes by VSCode Instead of git stash
Rei Yoshizawa
Rei Yoshizawa

Posted on • Originally published at reiyoshizawa.com

Discard File Changes by VSCode Instead of git stash

This is a small tip for anyone who uses git command daily.

How do you manage when you don't want file changes to be staged but need to checkout another branch?

I have usually cleared a branch by using git stash. git stash is not for discarding unnecessary files but for storing the file changes for just a temporary moment.

I knew that this way would not be ideal but didn't know the proper way of that.

Lately, I have found a much simple solution to discard file changes. Everyone should use that.

Image from Gyazo

Discard file changes

  1. Use Visual Studio Code
  2. Select Sorce Control in the left option (with shortcut key, Control + Shift + G)
  3. Click Discard All Changes

That's it! If you have specific files to discard, You only need to select that file.

I'm not familiar with this type of superpower of VSCode. If you know about VSCode tips to improve productivity, Please let me know. I would really appreciate it. Thanks!

Top comments (1)

Collapse
 
sanjarcode profile image
Sanjar Afaq • Edited

Theere is proper way to do undo via terminal

For unstaged changes

git checkout pathToFileOrFolder
git checkout src/component/Button.js #example
Enter fullscreen mode Exit fullscreen mode

For staged changes

git restore --staged pathToFileOrFolder # first unstage file

git checkout pathToFileOrFolder # then revert changes
Enter fullscreen mode Exit fullscreen mode

I use these shortands

PS: feel free to add to your article