Visual Studio 2015 Update 2 adds support for GIT "Reset", which is what you probably want to do:

  • open history
  • right click the commit you want to revert to
  • reset -> reset and delete changes

Answer from Runar Jordahl on Stack Overflow
🌐
DEV Community
dev.to › thebernardlim › git-how-to-edit-or-remove-a-pushed-commit-using-visual-studio-2876
Git - How to edit or remove a "pushed" commit using Visual Studio - DEV Community
January 13, 2023 - (Just for reference, I am using Visual Studio 2022) Removing your previous commit from your local repo using Reset · On the menu bar in Visual Studio, click on Git -> View Branch History.
Discussions

git - Is there a way to revert to a previous commit in VS code? - Stack Overflow
Is there a way to revert to a previous git commit in VS code? I know I can see the changes between commits and the differences in the working tree but I want to know how to reset to the previous co... More on stackoverflow.com
🌐 stackoverflow.com
git reset - How can I undo pushed commits using Git? - Stack Overflow
I have a project in a remote repository, synchronized with a local repository (development) and the server one (production). I've been making some committed changes already pushed to remote and pul... More on stackoverflow.com
🌐 stackoverflow.com
How do I undo an accidental Git Commit in VS ?
Undo changes in your Git repo - Azure Repos | Microsoft Docs More on reddit.com
🌐 r/VisualStudio
5
2
November 17, 2020
git - Possible to undo a commit in Visual Studio? - Stack Overflow
I am using VS 2022. I create a new branch and do some work on it. Click Commit All and realised i have included some things i dont want to push to the repository. Is there a way to undo this commit... More on stackoverflow.com
🌐 stackoverflow.com
🌐
YouTube
youtube.com › watch
How to Undo a Pushed Commit in Git Using Visual Studio (Beginner's Tutorial) - YouTube
Course link: https://aicourse.thinkific.com/courses/mastering-github-a-comprehensive-guideIn this video, we’ll show you how to undo a pushed commit in Git us...
Published   December 16, 2024
🌐
Microsoft Learn
learn.microsoft.com › en-us › visualstudio › version-control › git-manage-repository
Manage Git repos in Visual Studio | Microsoft Learn
To do the same in Visual Studio, right-click the commit you want to revert and then select Revert. After you confirm your action and the operation is complete, Visual Studio displays a success message and a new commit appears in the Outgoing section.
🌐
Microsoft Learn
learn.microsoft.com › en-us › azure › devops › repos › git › undo
Undo changes in your Git repo - Azure Repos | Microsoft Learn
If the file is in the Changes section, right-click it and choose Undo Changes to discard all changes to the file since the last commit. Visual Studio supports discarding uncommitted changes to a file by reverting the file to its last committed ...
Top answer
1 of 16
1910

You can revert individual commits with:

git revert <commit_hash>

This will create a new commit which reverts the changes of the commit you specified. Note that it only reverts that specific commit, and not commits that come after that. If you want to revert a range of commits, you can do it like this:

git revert <oldest_commit_hash>..<latest_commit_hash>

It reverts all the commits after <oldest_commit_hash> up to and including <latest_commit_hash>. Some versions of git also revert the <oldest_commit_hash> itself, so double check if that commit gets reverted or not. You can always drop the latest revert commit (which reverts the oldest commit) with g reset --hard HEAD~.

To find out the hash of the commit(s) you can use git log.

Look at the git-revert man page for more information about the git revert command. Also, look at this answer for more information about reverting commits.

Extra note for re-applying reverted commits:

Usually you revert commits because you discovered the commits that you pushed turn out to have an issue. Then you first want to restore the repo to a stable state, before you continue to fix the issue. So then you would first do the git revert, as described before. Then push those revert commits, so the remote is stable. After that you would want to re-apply the reverted commits locally, so your local repo's files are back to the state before the revert. Then you can fix the issue.

To re-apply the reverted commits, you have to revert the revert commits. So what you would do, is to again execute the git revert command, but then with the range of commits of the revert commits. So your new revert commits will revert the previous revert commits. Then your files are back to the state before the first revert. Then you can fix the issue, create a new commit with the fix, and then push all the new commits.

2 of 16
870

A solution that keeps no traces of the "undo".

NOTE: Don't do this if someone already pulled your change (I would use this only on my personal repo.)

Run:

git reset <previous label or sha1>

Note: previous means the commit before the erroneous commit

This will re-checkout all the updates locally (so git status will list all updated files, meaning, the files you changed/added/.. and were committed).

Then you "do your work" and re-commit your changes (Note: This step is optional).

git commit -am "blabla"

At this moment your local tree differs from the remote

git push -f <remote-name> <branch-name>

will force the remote branch to take this push and remove the previous one (specifying remote-name and branch-name is not mandatory but is recommended to avoid updating all branches with update flag).

!! Watch-out some tags may still be pointing removed commit !! how-to-delete-a-remote-tag

🌐
GitKraken
gitkraken.com › home › learn › problems & solutions › how to revert a git commit
Git Revert Commit | Solutions to Git Problems
February 5, 2024 - Learn how to use Git revert to undo changes introduced in a specified commit or group of commits. See examples of Git revert commit in the terminal, GitKraken Client, & GitLens.
Find elsewhere
🌐
Visual Studio Code
code.visualstudio.com › docs › sourcecontrol › faq
Source Control FAQ
November 3, 2021 - This topic answers frequently asked questions about using Git source control and GitHub in Visual Studio Code. Revert your last commit with the Git: Undo Last Commit command. This will reset your branch to the state right before you did the ...
🌐
LinkedIn
linkedin.com › learning › visual-studio-source-control-with-git-and-github › when-to-use-revert-or-reset
When to use revert or reset - Visual Studio Video Tutorial | LinkedIn Learning, formerly Lynda.com
March 1, 2020 - To get to these actions in Visual Studio, go to History, and then right click on one of the commits. There's two choices, Revert, and Reset with two options, Reset, Keep Changes and Reset, Delete Changes.
Top answer
1 of 2
3

You were just about there:

I opened up Git > Manage Branches and see the commit i did and see a couple of options.

You'll want to learn more about the different git reset options and how they work, but the two reset options that Visual Studio offers are --mixed and --hard. To use the reset option, in the branch history graph, select the commit that you wish to reset your branch pointer to, and this will remove all of the commits above it (and if a merge commit is being removed it will also remove all commits brought in by that merge).

For your use case where you have one commit that you wish to remove, and re-commit some of it, select the parent commit of that commit (the one below your commit in the graph), right click on it, and select "Reset->Keep Changes (--mixed)". This will put you back into the state you were in before you created the commit, with nothing staged yet.

Side Notes:

  • If you don't want to keep any of your changes, you should choose --hard.
  • Note that VS doesn't offer the option to do a --soft reset in the GUI, but the only difference with --soft is that all your changes would be staged already, which you can manually do in the GUI after reset with --mixed.
  • The GUI command is identical to running the following command from the command line, e.g. a mixed reset: git reset --mixed <selected-commit-id>
2 of 2
0

You can effect an undo from within VS, but it's not an actual undo, it's a compensating commit that reverts you back to the prior state of the offending commit.

From the Search dropdown in the main menu select Feature Search. Type in View History or View Branch History and select that. A history of your commits will be listed. Right click the commit you want to undo and choose Revert.

I'd show a screenshot but I'd have to redact everything.

🌐
Sara Ford's Blog
saraford.net › 2017 › 03 › 26 › how-to-revert-changes-in-visual-studio-085
How to revert changes in Visual Studio – 085 - Sara Ford's Blog
March 26, 2017 - Going to the history shows where this change was introduced, i.e. “added ChangeColors()”. You can revert this commit by right-click and selecting “Revert.”
🌐
Developer Community
developercommunity.visualstudio.com › idea › 728035 › undo-last-commit.html
Undo last commit - Developer Community
Skip to main content · Visual Studio · Guidelines Problems Suggestions Code of Conduct · Downloads · Visual Studio IDE Visual Studio Code Azure DevOps Team Foundation Server Accounts and Subscriptions · Subscriber Access · Microsoft Security Azure Dynamics 365 Microsoft 365 Microsoft ...
🌐
O'Reilly
oreilly.com › library › view › mastering-visual-studio › 9781787281905 › 3e457f08-86e0-4d20-930b-f15e63ebc596.xhtml
Reverting changes from remote branch - Mastering Visual Studio 2017 [Book]
July 27, 2017 - When you have pushed some commits to the remote repository and would like to undo those changes, you need to use the revert command to create a new commit, undoing all those changes.
Author   Kunal Chowdhury
Published   2017
Pages   466
🌐
DEV Community
dev.to › github › how-to-undo-pushed-commits-with-git-2pe6
How to Undo Pushed Commits with Git - DEV Community
April 6, 2022 - If you’re seeing this message ... that you’ve exited the terminal, you can finalize the process by running the command git push. After running this command, you’ve successfully reverted your commit....
🌐
Bobby Hadz
bobbyhadz.com › blog › vscode-undo-last-git-commit
How to Undo the last Git Commit in Visual Studio Code | bobbyhadz
April 6, 2024 - Type GitLens. Make sure you have the extension installed. ... Click on the Source Control icon and expand the COMMITS menu. Right-click on the commit you want to revert and select Revert Commit....
🌐
Graphite
graphite.com › guides › git-revert-commit-after-pushing
git revert commit after pushing - Graphite
Simply use git revert on the revert commit hash: ... To revert multiple commits in reverse chronological order (newest first), you can revert them one by one: ... Whether you've made a mistake in your commit or simply want to modify it before ...