Forum Discussion

Descrierx's avatar
Descrierx
Copper Contributor
Nov 05, 2019

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

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

  • chilberto's avatar
    chilberto
    Iron Contributor

    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

     

     

    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:

     

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

     

    The command to https://mirrors.edge.kernel.org/pub/software/scm/git/docs/git-revert.html 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:

     

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

     

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

     

    Cheers,

    Jeff

     

     

Resources