Text of code.visualstudio.com › docs › sourcecontrol › staging-commits as Styx crawled it on Nov 18, 2026. The page may have changed since. Only its words are kept, without pictures or layout, and only the first part of a long page.

Open the live page

Staging and committing changes

AI agents: See llms.txt for documentation discovery and navigation. Documentation articles are also available as Markdown by appending .md to the article URL. Join VS Code at Microsoft Ignite or catch the sessions online. A year of VS Code, wrapped. Explore the highlights. Staging and committing changes View as Markdown Ask in VS Code Ask in VS Code Insiders Use the Source Control view in VS Code to choose exactly which changes go into a commit.

This guide covers reviewing files, staging individual changes, committing, and choosing an undo action. New to Git? Follow the first-commit quickstart to set up a practice repository and configure your commit identity. For a specific task, jump to partial staging , committing , or undo and discard options . Git workflow Saving a file, staging it, committing it, and pushing it are separate operations: Action Result Save Writes your edits to the working file on disk.

Stage Copies selected changes into the staging area, also called the index. Commit Records the staged snapshot in local Git history. Push Uploads local commits to a remote repository. Staging captures the selected content at that moment. If you edit the file again, those later edits are not included in the staged snapshot until you stage them too. View changes The Source Control view ( ⌃⇧G (Windows, Linux Ctrl+Shift+G ) ) is your central hub for managing changes in your Git repository.

Changes are organized into two sections based on their staging status: Changes : lists all modified, added, or deleted files that are not yet staged for commit Staged Changes : lists files that have been staged and are ready to be committed Notice that changed files are listed with a "U" (untracked), "M" (modified), or "D" (deleted) icon next to them to indicate the type of change. This change indicator is also shown in the Explorer view and in the editor tab title for modified files.

The source control icon in the Activity Bar also shows a badge with the number of affected files to give you a quick overview of your uncommitted changes. Tip You can view the list of changes in either a flat or tree structure. Toggle this with the More Actions ( ... ) > View & Sort > View as Tree/List option in the Source Control view toolbar. Why a file appears in both lists A file can have both staged and unstaged changes.

For example: Edit a tracked file and stage it. Edit the same file again and save it without staging. The file now appears in both lists. Select it in Staged Changes to see the first edit, which is ready to commit. Select it in Changes to see the later edit, which is not included in that commit. Stage the file again to include both edits, or commit the staged version and leave the later edit for another commit. Unstaging preserves both edits in your working file.

Staging changes Staging changes prepares them for adding to your next commit. You can stage entire files or specific lines and code blocks for more granular control. To stage individual files, hover over them in the Changes list and select the + (plus) icon, or right-click the file and select Stage Changes . You can also drag files from the Changes section and drop them into the Staged Changes section to stage them. When you're using the tree view, you can stage entire folders by staging the folder itself.

To stage all modified files at once, hover over the Changes header and select the + (plus) icon. There are more specialized staging actions available in the Command Palette ( ⇧⌘P (Windows, Linux Ctrl+Shift+P ) ). Type "Git: Stage" to see options for staging files. Stage specific lines or code blocks Instead of staging entire files, you can also stage specific parts of a file. Partial staging enables you to create focused commits.

For example, if you've made formatting changes and bug fixes in the same file, you can commit them separately with appropriate commit messages. You can perform partial staging from the diff editor: Select a file in the Changes list to open the diff editor . Select the lines you want to stage. Use the Stage button in the gutter of the diff editor next to your selection to stage only those lines. You can also right-click the selection and choose Stage Selected Ranges or run Git: Stage Selected Ranges from the Command Palette.

Unstage changes To remove files from staging, hover over them in the Staged Changes list and select the - (minus) icon, or right-click and choose Unstage Changes . The files move back to the Changes section without losing your modifications. Similarly, you can also unstage specific lines or code blocks from the diff editor using the Unstage button in the gutter next to your selection. Commit your changes Select each file in Staged Changes to review the content that will be committed.

Enter a message in the commit message input box that describes the change, such as Fix validation for empty names . Select Commit . The committed changes disappear from Staged Changes and appear in the Source Control Graph . Unstaged edits remain in Changes . The commit is local until you push it . If Git asks you to configure your name or email, follow the quickstart prerequisites . Write commit messages A commit message helps others understand what changed and why.

Use a short summary for the first line. For a longer explanation, use the editor for commit messages . Tip To cycle through your previous commit messages, press ↑ (Windows, Linux Up ) and ↓ (Windows, Linux Down ) while focused in the commit message input box. Commit changes The Commit button uses your staged changes. If nothing is staged, the behavior depends on your Git settings and VS Code can prompt you to stage changes.

Stage explicitly when you want to control the commit's contents. To commit all changes at once, select More Actions ( ... ) > Commit > Commit All . Review all pending files before using this action. Undo or discard changes Choose the action that matches the state of your work. Unstaging, undoing a commit, and discarding edits have different effects. Goal Action Effect Keep edits but remove them from the next commit Unstage Preserves working files.

Correct the most recent unpushed commit Amend Replaces that commit with a new one. Remove the most recent unpushed commit but keep its changes Undo Last Commit Changes local history and preserves edits. Reverse a commit already shared with others Revert the commit Adds a new commit without rewriting shared history. Remove uncommitted edits Discard Removes work. Recovery is not guaranteed. Amend the previous commit If you need to modify your most recent commit, you can amend it instead of creating a new commit.

This is useful for adding forgotten changes or correcting the commit message. To amend a commit, select the Commit button dropdown and select Commit (Amend) , or use the Commit Staged (Amend) option from the More Actions ( ... ) menu. Caution Only amend commits that haven't been pushed to a shared repository. Amending pushed commits rewrites history and can cause issues for other collaborators. Undo the last commit For a commit you haven't pushed, select More Actions ( ... ) > Commit > Undo Last Commit in the Source Control view.

The commit is removed from local branch history and its changes remain staged so you can edit or commit them again. If you undo the repository's first commit, its files become untracked instead. Don't use this action to undo shared history. Revert a pushed commit instead. Undo a pushed commit Reverting creates a new commit that reverses an earlier commit. It preserves the shared history and does not require a force push.

For a regular, non-merge commit: Open the branch containing the commit. Commit or stash any pending changes before continuing. Find the commit's hash in the Source Control Graph , or run git log --oneline in the integrated terminal. Run the following command in the repository's terminal, replacing <commit-hash> with that hash: git revert --no-edit < commit-has h> If successful, Git creates a n

The rest of this page is on the live site.