Viewing Changes & Undoing Changes
Every developer faces moments when code changes go awry. Whether it's a misguided refactor or an accidental deletion, knowing how to efficiently rollback changes is essential for maintaining clean project history and your sanity. Git's robust undo mechanisms, combined with Visual Studio Code's intuitive interface, provide multiple pathways to recovery depending on your specific situation.
Undo Local Changes That Have Not Been Committed
When you've made changes that haven't been committed yet—perhaps experimental code that didn't pan out or modifications that broke functionality—you can quickly discard them without affecting your repository's history. This is the cleanest form of undoing changes since no commit record exists.
- In the Source Control panel
you'll see files that have been modified, marked with an 'M' indicator next to their names. - Hover over any file containing unwanted changes and click the Discard Changes button
that appears. This action is immediate and irreversible for uncommitted work. When prompted for confirmation, click Discard Changes to proceed.
The file immediately reverts to its state at the last commit, permanently erasing your uncommitted modifications. This clean slate approach is particularly useful during exploratory coding sessions or when testing different implementation approaches.
Before diving into more complex undo operations, you'll want to enhance Visual Studio Code's Git capabilities with a powerful visualization tool.
Discard Uncommitted Changes
Open Source Control Panel
Navigate to the Source Control panel where you can see all modified files that haven't been committed yet.
Hover Over Changed Files
Find files containing unwanted changes and hover over them to reveal the action buttons.
Discard Changes
Click the Discard Changes button and confirm to revert the file to its previous committed state.
Install the Git Graph Extension for Visual Studio Code
The Git Graph extension transforms Git from a command-line abstraction into a visual, interactive experience. This tool becomes indispensable when working with complex branching strategies or when you need to understand the relationship between commits across time.
On the left side of the Visual Studio Code window, click the Extensions icon
to open the Extensions marketplace.- In the search field, type: Git Graph
Locate the Git Graph extension by mhutchie (which has over 4 million downloads) and click Install.
Once installed, Git Graph provides the visual context necessary for the more sophisticated undo operations that follow.
Git Graph Extension Benefits
Visual Commit History
View your Git history in an intuitive graphical interface that makes understanding your project timeline easier.
Enhanced File Tracking
Click on commits to see exactly which files were changed and review the specific modifications made.
Advanced Git Operations
Access powerful Git commands like drop and revert directly from the visual interface with right-click context menus.
View a List of Commits
Understanding your project's commit history is crucial before making any undo decisions. The Git Graph extension transforms this typically abstract concept into an intuitive visual timeline, showing not just what changed, but when and why.
Towards the bottom left of the window (in the status bar), click Git Graph.
Alternatively, at the top of the Source Control panel
you can click the View Git Graph button for quick access.In the Git Graph tab that opens, you gain comprehensive visibility into your repository's evolution:
- Scan commit messages to identify specific changes or problematic commits.
- Click any commit to reveal which files were modified, providing immediate context about the scope of changes.
- Click individual file names within a commit to see exact line-by-line modifications, helping you understand the precise impact of each change.
Now that you can visualize your commit history, let's explore different undo strategies based on whether your changes have been shared with others.
Git Graph Access Methods
| Feature | Blue Bar Method | Source Control Method |
|---|---|---|
| Location | Bottom left blue bar | Top of Source Control panel |
| Button Name | Git Graph | View Git Graph |
| Convenience | Always visible | Context-specific |
Undo Your Last Commit (That Has Not Been Pushed)
Sometimes you commit too hastily—perhaps forgetting to include a crucial file or realizing you made a mistake immediately after committing. When the problematic commit hasn't been pushed to a remote repository, you can cleanly undo it without affecting collaborators or creating messy history.
At the top right of the Source Control panel
click the More Actions button
and from the dropdown menu choose Commit > Undo Last Commit.Your most recent commit disappears from history, but your changes remain intact and return to their staged state. This gives you the flexibility to unstage specific files, make additional modifications, or reorganize your changes before creating a new, more thoughtful commit. This approach maintains a clean, professional commit history that your future self and teammates will appreciate.
Undoing your last unpushed commit keeps your Git history cleaner by allowing you to fix mistakes before they become part of the permanent record.
After Undoing Last Commit
Your changes remain staged, allowing you to unstage specific files if needed
Include any files you originally forgot in the previous commit
Edit files further before creating your corrected commit
Make a proper commit with all necessary changes included
Undo a Specific Commit (That Has Not Been Pushed)
When you need to remove a specific commit from your local history—perhaps a experimental feature that didn't work out or a commit that introduced bugs several changes ago—the "drop" operation completely erases it as if it never existed. This nuclear option is only available for unpushed commits, preserving the integrity of shared repository history.
You'll need the Git Graph extension installed for this visual approach to work effectively.
Towards the bottom left of the window (in the status bar), click Git Graph.
Alternatively, access it through the Source Control panel
by clicking the View Git Graph button.Before dropping any commit, thoroughly investigate its contents to avoid unintended consequences:
- Review commit messages to understand the purpose and scope of each change.
- Click on commits to examine which files were affected.
- Click individual file names to see specific modifications and assess their importance.
- Close the file diff tabs to return to the Git Graph overview when you're ready to take action.
- Once you've identified the problematic unpushed commit, right-click (Windows/Linux) or Ctrl-click (Mac) on the commit name and select Drop from the context menu.
Confirm your decision when prompted—this action is irreversible.
The commit vanishes entirely from your repository's history, and all associated changes are permanently removed from your files. It's as if the commit never existed, providing the cleanest possible resolution for unwanted changes.
However, once commits have been pushed and potentially pulled by collaborators, the approach must be more conservative to maintain repository integrity.
Drop Unpushed Commits
Analyze Commit History
Review commit messages and examine file changes to identify which commits should be removed from your history.
Right-Click Target Commit
Use CTRL-click on Mac or Right-click on Windows to access the context menu for the commit you want to drop.
Confirm Deletion
Select Drop from the menu and confirm the action to completely remove the commit and reverse its changes.
Undo a Specific Commit (That Has Been Pushed)
When dealing with problematic commits that have already been pushed to a shared repository, you can't simply erase history without potentially disrupting other developers' work. Instead, Git's revert operation creates a new commit that undoes the changes, maintaining a complete audit trail while safely neutralizing unwanted modifications.
This approach requires the Git Graph extension for optimal workflow visualization.
Access the commit history by clicking Git Graph in the status bar at the bottom left of your window.
You can also reach this through the Source Control panel
via the View Git Graph button.Conduct thorough due diligence before reverting any pushed commit:
- Examine commit messages to understand the original intent and potential dependencies.
- Click commits to see affected files and assess the breadth of changes.
- Review individual file modifications to understand exactly what will be undone.
- Close diff tabs to return to the main Git Graph interface when ready to proceed.
- After identifying the commit to revert, right-click (Windows/Linux) or Ctrl-click (Mac) on the commit name and choose Revert from the context menu.
Confirm the revert operation when prompted.
Git creates a new commit that precisely undoes all changes from the target commit, effectively neutralizing its impact while preserving the historical record. This transparency is crucial for team environments and audit trails.
Important: If the revert creates merge conflicts—common when subsequent commits modified the same code—you'll need to manually resolve these conflicts before completing the revert commit. Visual Studio Code's built-in merge conflict resolution tools will guide you through this process.
Push the revert commit when you're ready to share the fix with your team, ensuring everyone receives the corrected codebase.
Revert vs Drop for Pushed Commits
When reverting pushed commits, you may encounter conflicts that need manual resolution before creating the revert commit.
Another Git Extension for Visual Studio Code
For developers seeking even more sophisticated Git integration, GitLens represents the premium tier of version control tooling within Visual Studio Code. This extension transforms your editor into a comprehensive Git workstation, providing contextual information that helps you understand code evolution at a granular level.
Navigate to the Extensions panel by clicking the Extensions icon
on the left sidebar.- Search for: GitLens
Install the GitLens extension by GitKraken (which boasts over 24 million downloads as of 2026).
GitLens elevates your development workflow with powerful features that provide unprecedented visibility into your codebase:
- Enriches the Source Control panel
with dedicated sections for Commits, File History, Branches, Remotes, and more, creating a comprehensive Git dashboard. - Adds intuitive navigation controls at the top right of your editor window, enabling quick traversal through changes and comparisons between different versions.
- Provides inline blame annotations that appear as you code, showing who last modified each line, when the change occurred, and the associated commit message—invaluable for understanding code context and tracking down the source of issues.
Git Graph vs GitLens Extensions
| Feature | Git Graph | GitLens |
|---|---|---|
| Primary Focus | Visual commit history | Comprehensive Git integration |
| UI Additions | Git Graph tab | Multiple panels and buttons |
| Code Annotations | Limited | Inline blame information |
| Learning Curve | Simple | More complex |
GitLens Advanced Features
Enhanced Source Control Sections
Adds dedicated panels for Commits, File History, Branches, and other Git operations directly in Source Control.
Navigation Controls
Provides additional Git buttons in the top-right window area for quick navigation between changes and commits.
Inline Code Attribution
Shows author, date, and commit information directly in your code editor for every line you're currently viewing.