Optional
Source control
Manage local changes by saving them for later or discarding them when they are no longer needed.
Open changes
Open the Source Control view to see files that have changed since the last commit.
The number on the Source Control icon and next to Changes shows how many files currently have changes.
Click a file under Changes to inspect what changed.
VS Code opens a comparison view. The left side shows the previous version, and the right side shows the current working tree. Red highlights show removed or previous content, while green highlights show added or current content.
Stash
If you want to temporarily save your changes, you can use the ‘stash’ feature in Source Control. Stashing can be useful for version control purposes.
To create a stash, click on ‘Stash’.
To apply a stash, click on ‘Apply Stash’.
Discard Changes
If you want to discard the changes, you can simply click on the following buttons in the source control.
To discard all changes, click the button next to Changes.
Undo local commits
If you already committed by mistake but have not pushed yet, you can undo the commit and return the files to unstaged changes.
For example, after making a mistaken commit, Source Control may show a Sync Changes 1↑ button. This means one local commit is waiting to be pushed.
To undo only the latest local commit, run:
git reset --mixed HEAD~1
This command cancels the latest commit, keeps the file changes, and returns those changes to the unstaged area.
After the reset, the files appear under Changes again.
To undo the latest two local commits, change the number:
git reset --mixed HEAD~2
Use this only for commits that have not been pushed yet. If the commit has already been pushed or shared with others, do not reset it unless you understand the consequences.
Before you discard changes, apply a stash, or reset a local commit, check the current state first:
git status
If the current work might still matter, save it in a commit, stash it, or copy the important text elsewhere before running commands that remove or rewrite local history.