How to bring master branch to previous state in azure devops git

Copper Contributor
I am really a noob in handling azure devops git as it is my first time working on CI/CD pipeline build and so I really need your help.I first mistakenly committed to the master branch and den to rectify it ,reverted a wrong commit.See how noob I can be.Little scared I have become ,please let me know how to revert master branch to previous state i.e. before my commit
1 Reply

Hello @Descrierx,

 

I know how working with DevOps and Git can be overwhelming to start. The most important thing is to get your code base back to how it should be. Secondary to that is having a history that reflects this.

 

Based on your description, I did the similar activity:

  1. Added an incorrect commit
  2. reverted the wrong commit
  3. merged this back

 

clipboard_image_0.png

 

So, in my example, I want to get back to the commit 454456cb. There are multiple ways. The recommended way would be to revert the incorrect commits so you are back to 454456cb. This will mean you have the history including the whoops!. Another approach is to reset back to the last good commit.

 

Let's show both using git bash. First I cloned the repo done to a new folder:

clipboard_image_1.png

 

If I use git log then I can see that I have all the commits:

clipboard_image_2.png

 

The command to revert multiple commits is: git revert --no-edit -n c7c695fb..c0ea7366

 

The other approach (and only use if you really want to remove the history) uses a hard reset to the last good changeset:

clipboard_image_3.png

 

Going back to my history, you can see everything is now back to how it was:

clipboard_image_4.png

 

Hope this helps; if so, please mark as answer.

 

Cheers,

Jeff