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.

VS Code Source Control view showing changed files

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.

Changed file selected in VS Code Source Control

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.

VS Code comparison view showing old and current file versions

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’.

VS Code Source Control stash command

To apply a stash, click on ‘Apply Stash’.

VS Code Source Control apply stash command

Discard Changes

If you want to discard the changes, you can simply click on the following buttons in the source control.

VS Code Source Control discard changes buttons

To discard all changes, click the button next to Changes.

VS Code Source Control discard all changes button

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.

VS Code Source Control before making a mistaken commit
VS Code Source Control showing one local commit waiting to sync

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.

Terminal running git reset mixed HEAD one commit back

After the reset, the files appear under Changes again.

VS Code Source Control showing files returned to unstaged changes

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.