Optional

Source control

On Windows, inspect file changes in VS Code Source Control, save unfinished work for later, or discard unwanted changes. You can also undo a local commit that has not been published.

Open changes

On Windows, press Ctrl+Shift+G to open Source Control and see modified, added, or deleted files. Changes lists files that are not staged; Staged Changes lists files selected for the next commit.

VS Code Source Control view showing changed files

The Source Control badge summarizes changed items in the repository. The number beside Changes counts items that have not been staged.

Select a file under Changes to inspect its changes.

Changed file selected in VS Code Source Control

In a side-by-side diff, the last committed file appears on the left and the current working file on the right. A narrow editor may show an inline diff instead. Use the added and removed line indicators to inspect the change.

VS Code comparison view showing old and current file versions

Save changes with Stash

Use a stash to put uncommitted changes aside while you handle another task. A stash stays local and is not uploaded to GitHub by Push. Press Ctrl+Shift+P, run Git: Stash, and enter a descriptive message. To include new, untracked files as well, choose Git: Stash (Include Untracked).

The older screenshot below also shows generated .aux, .log, and .pdf files. Check whether a new file belongs in the stash before including it; use Gitignore rules for generated files you normally exclude from commits.

Older VS Code Source Control menu showing the Stash command beside generated files

Use Git: View Stash to inspect a stash first. Git: Apply Stash... restores the selected changes and keeps the stash entry; Git: Pop Stash... removes the entry after applying it successfully. Resolve any conflicts with current work before continuing.

Older VS Code Source Control menu showing Apply Latest Stash and Apply Stash commands

Discard Changes

To discard uncommitted changes in one file, right-click it under Changes and select Discard Changes. A new, untracked file has no earlier version to restore and may be removed, so check the target first.

Older Source Control screen highlighting the discard action for an untracked file

The discard button beside Changes discards changes across the list. Use the file action when you only intend to discard one file, and review the confirmation dialog’s file list before discarding everything.

Older Source Control screen highlighting the discard action for the entire Changes list

Undo local commits

If you made the last commit but have not pushed it, you can remove that commit while keeping its file changes in your working folder. First check the current branch and the commit you intend to undo.

In the example below, Sync Changes 1↑ means the local branch is one commit ahead of its remote branch. Confirm that the commit has not been pushed before continuing.

Older VS Code screen preparing to commit seven new image files and one modified file
Older VS Code screen showing Sync Changes 1↑ for a local branch one commit ahead of the remote

To undo only the latest unpublished commit on the current branch, run this command in the integrated terminal:

git reset --mixed HEAD~1

This command moves the current branch back one commit and resets the staging area while keeping the working files. Modified existing files appear under Changes; files first added in the undone commit may appear as untracked files.

Older PowerShell terminal running git reset --mixed HEAD~1

After the reset, inspect the remaining files in Source Control and stage only those you still need.

Older VS Code screen showing modified and untracked files in Changes after Reset

Do not use this Reset command for a commit that has already been pushed or shared. If you need a new commit that reverses published changes, see the Git revert documentation.

Before discarding changes, applying a stash, or resetting a commit, run git status to review modified, staged, and untracked files. Preserve work you might need in a separate commit or copy first.

git status

Image preview