Skip to main content
March 23, 2026Dan Rodney/7 min read

View a List of Commits & Undo Changes

Master Git Version Control in Visual Studio Code

Git Version Control Fundamentals

Understanding how to view and undo changes is essential for maintaining clean code history and recovering from mistakes in your development workflow.

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.

  1. In the Source Control panel vscode soure control icon you'll see files that have been modified, marked with an 'M' indicator next to their names.
  2. Hover over any file containing unwanted changes and click the Discard Changes button vscode discard changes icon that appears. This action is immediate and irreversible for uncommitted work.
  3. 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

1

Open Source Control Panel

Navigate to the Source Control panel where you can see all modified files that haven't been committed yet.

2

Hover Over Changed Files

Find files containing unwanted changes and hover over them to reveal the action buttons.

3

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.

  1. On the left side of the Visual Studio Code window, click the Extensions icon vscode extensions icon to open the Extensions marketplace.

  2. In the search field, type: Git Graph
  3. 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.

  1. Towards the bottom left of the window (in the status bar), click Git Graph.

    Alternatively, at the top of the Source Control panel vscode soure control icon you can click the View Git Graph button for quick access.

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

FeatureBlue Bar MethodSource Control Method
LocationBottom left blue barTop of Source Control panel
Button NameGit GraphView Git Graph
ConvenienceAlways visibleContext-specific
Recommended: Use the blue bar method for quick access, or the Source Control panel when already working with version control.

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.

  1. At the top right of the Source Control panel vscode soure control icon click the More Actions button vscode more actions icon and from the dropdown menu choose Commit > Undo Last Commit.

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

Clean History Strategy

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

0/4

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.

  1. Towards the bottom left of the window (in the status bar), click Git Graph.

    Alternatively, access it through the Source Control panel vscode soure control icon by clicking the View Git Graph button.

  2. 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.
  3. 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.
  4. 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

1

Analyze Commit History

Review commit messages and examine file changes to identify which commits should be removed from your history.

2

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.

3

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.

  1. 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 vscode soure control icon via the View Git Graph button.

  2. 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.
  3. 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.
  4. 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.

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

Pros
Maintains complete audit trail of all changes
Safe for collaborative environments with multiple developers
Preserves Git history integrity
Can be easily undone if revert was applied incorrectly
Cons
Creates additional commits in history
May require conflict resolution if other changes conflict
Original bad commit remains visible in history
Requires push to share revert with team
Conflict Resolution Required

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.

  1. Navigate to the Extensions panel by clicking the Extensions icon vscode extensions icon on the left sidebar.

  2. Search for: GitLens
  3. 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 vscode soure control icon 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

FeatureGit GraphGitLens
Primary FocusVisual commit historyComprehensive Git integration
UI AdditionsGit Graph tabMultiple panels and buttons
Code AnnotationsLimitedInline blame information
Learning CurveSimpleMore complex
Recommended: Start with Git Graph for essential features, then add GitLens for advanced Git workflow management.

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.

Key Takeaways

1Use the Source Control panel to discard uncommitted changes by hovering over files and clicking the Discard Changes button
2Install Git Graph extension to visualize commit history and perform advanced Git operations through an intuitive interface
3Access Git Graph either through the blue bar at bottom-left or the View Git Graph button in Source Control panel
4Undo your last unpushed commit using More Actions > Commit > Undo Last Commit to maintain clean Git history
5Drop unpushed commits by right-clicking them in Git Graph and selecting Drop to completely remove them from history
6Revert pushed commits by right-clicking and selecting Revert, which creates a new commit that undoes the changes
7Handle merge conflicts manually when reverting commits that conflict with subsequent changes before making new commits
8Consider GitLens extension for advanced features like inline code attribution, enhanced panels, and additional navigation controls

RELATED ARTICLES