15

I have a commit done by a developer in the remote Git repository hosted in VSTS that needs to be rolled back. From Visual Studio, without going to the command prompt or how to revert the commit?

I want to undo the commit through Visual Studio without using a command prompt.

Edward Thomson
  • 74,857
  • 14
  • 158
  • 187
Edvaldo Silva
  • 904
  • 2
  • 16
  • 29
  • It would be better to apply a new commit that restored the repository to a previous state instead of retroactively rewriting history by "deleting" the last commit. – Dai Aug 23 '17 at 19:31
  • 1
    Possible duplicate of [How to revert Git repository to a previous commit?](https://stackoverflow.com/questions/4114095/how-to-revert-git-repository-to-a-previous-commit) – Dai Aug 23 '17 at 19:31
  • 1
    Also, why are you opposed to using the git command-line? It's the best way to become familiar with how git works - the GUI built-in to Visual Studio hides many important details that I personally feel are necessary for the inexperienced to be exposed to. – Dai Aug 23 '17 at 19:32
  • 1
    Please read the entire question before voting as dublicated. I want to undo the commit through Visual Studio without using a command prompt. @Dai – Edvaldo Silva Aug 23 '17 at 21:31
  • I already know how to do it from the command prompt, but I need to know how to do it inside Visual Studio. – Edvaldo Silva Aug 23 '17 at 21:35

2 Answers2

22

Selected answer is not correct. In order to undo a commit you need to select reset, not revert. Revvert will make a new commit with code contained in previous commit. Where reset will actually delete the commits after the selected version.

AllenKll
  • 1,006
  • 2
  • 12
  • 23
  • 1
    The question literally asks how to _revert_ from the UI. It doesn’t ask how to “undo”, which itself would require explanation. – Edward Thomson Jul 20 '19 at 08:20
  • 6
    The question also literally asks how to _undo_. in fact it says the word _undo_ twice. I believe the OP was just using a synonym for _undo_ when he says _revert_, and in fact does not mean specifically a _git_ _revert_ command. – AllenKll Jul 21 '19 at 15:30
  • 1
    And it uses the word revert once, and again in a comment that explicitly mentions the command line. Your answer that explains the difference between revert and reset is useful, but your assumption that the OP wants to _do_ a reset doesn't have much basis. Regardless, as it stands, this is a _comment_ on an existing answer, not an _answer_ to the question itself. Showing how to both reset _and_ revert in Visual Studio would make this a very good answer to the question. – Edward Thomson Jul 21 '19 at 15:46
  • 3
    Regarding the difference between revert and reset, this answer is clearer than the one in MS documentation. – jcs Sep 27 '19 at 18:11
  • 3
    I wish your answer was the selected answer, now I've got an extra commit to somehow get rid of.... – Thomas Harris May 13 '20 at 15:33
  • This gets my vote. Not only is it clear and concise, but I agree that the word Undo in the title and "rollback" in the body mean it is more likely the OP was asking about a reset. This answer does not actually say HOW to reset, so it is not a complete answer but it is the closer of the two answers IMO. – EGP Jan 03 '23 at 19:25
12

Open the "Changes" tab in Team Explorer. Select "Actions", then "View History" to view the history of the repository. Identify the commit that you want to revert, right-click on it and select "Revert" from the context menu.

Revert

Edward Thomson
  • 74,857
  • 14
  • 158
  • 187
  • 1
    FWIW, http://gitforvisualstudio.com is some lovely training for Git in Visual Studio. (I must admit that I'm biased, though.) – Edward Thomson Aug 23 '17 at 21:43
  • Thanks for that link, that will certainly come in handy for coworkers in the future! ;) – poke Aug 23 '17 at 21:57
  • @EdwardThomson y'know what would be nice? If the context-menus for git operations had a tooltip that showed you the command-line equivalent of that menu option. So "Revert" would say "git revert {commit}`, for example. – Dai Aug 23 '17 at 22:52
  • Thanks for the feedback @Dai, I'll bring your suggestion to the team that works on the VS integration. – Edward Thomson Aug 23 '17 at 23:00
  • This doesn't work. This makes a new commit that indicates that a commit was reverted. this is not the same as undo-ing a commit. – AllenKll Jul 20 '19 at 04:47