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

%3CLINGO-SUB%20id%3D%22lingo-sub-983851%22%20slang%3D%22en-US%22%3EHow%20to%20bring%20master%20branch%20to%20previous%20state%20in%20azure%20devops%20git%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-983851%22%20slang%3D%22en-US%22%3EI%20am%20really%20a%20noob%20in%20handling%20azure%20devops%20git%20as%20it%20is%20my%20first%20time%20working%20on%20CI%2FCD%20pipeline%20build%20and%20so%20I%20really%20need%20your%20help.I%20first%20mistakenly%20committed%20to%20the%20master%20branch%20and%20den%20to%20rectify%20it%20%2Creverted%20a%20wrong%20commit.See%20how%20noob%20I%20can%20be.Little%20scared%20I%20have%20become%20%2Cplease%20let%20me%20know%20how%20to%20revert%20master%20branch%20to%20previous%20state%20i.e.%20before%20my%20commit%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-983851%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EDevOps%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-990139%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20bring%20master%20branch%20to%20previous%20state%20in%20azure%20devops%20git%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-990139%22%20slang%3D%22en-US%22%3E%3CP%3EHello%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F444988%22%20target%3D%22_blank%22%3E%40Descrierx%3C%2FA%3E%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20know%20how%20working%20with%20DevOps%20and%20Git%20can%20be%20overwhelming%20to%20start.%20The%20most%20important%20thing%20is%20to%20get%20your%20code%20base%20back%20to%20how%20it%20should%20be.%20Secondary%20to%20that%20is%20having%20a%20history%20that%20reflects%20this.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBased%20on%20your%20description%2C%20I%20did%20the%20similar%20activity%3A%3C%2FP%3E%3COL%3E%3CLI%3EAdded%20an%20incorrect%20commit%3C%2FLI%3E%3CLI%3Ereverted%20the%20wrong%20commit%3C%2FLI%3E%3CLI%3Emerged%20this%20back%3C%2FLI%3E%3C%2FOL%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F155458i7BB2ECBAF4D0B088%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20alt%3D%22clipboard_image_0.png%22%20title%3D%22clipboard_image_0.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESo%2C%20in%20my%20example%2C%20I%20want%20to%20get%20back%20to%20the%20commit%20454456cb.%20There%20are%20multiple%20ways.%20The%20recommended%20way%20would%20be%20to%20revert%20the%20incorrect%20commits%20so%20you%20are%20back%20to%20454456cb.%20This%20will%20mean%20you%20have%20the%20history%20including%20the%20%3CEM%3Ewhoops!.%26nbsp%3B%3C%2FEM%3EAnother%20approach%20is%20to%20reset%20back%20to%20the%20last%20good%20commit.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ELet's%20show%20both%20using%20git%20bash.%20First%20I%20cloned%20the%20repo%20done%20to%20a%20new%20folder%3A%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F155459iD2A48C478733C998%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20alt%3D%22clipboard_image_1.png%22%20title%3D%22clipboard_image_1.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20I%20use%20%3CEM%3Egit%20log%3C%2FEM%3E%20then%20I%20can%20see%20that%20I%20have%20all%20the%20commits%3A%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F155460i69D2921766859DB7%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20alt%3D%22clipboard_image_2.png%22%20title%3D%22clipboard_image_2.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20command%20to%20%3CA%20href%3D%22https%3A%2F%2Fmirrors.edge.kernel.org%2Fpub%2Fsoftware%2Fscm%2Fgit%2Fdocs%2Fgit-revert.html%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Erevert%3C%2FA%3E%20multiple%20commits%20is%3A%20git%20revert%20--no-edit%20-n%20c7c695fb..c0ea7366%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20other%20approach%20(and%20only%20use%20if%20you%20really%20want%20to%20remove%20the%20history)%20uses%20a%20hard%20reset%20to%20the%20last%20good%20changeset%3A%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F155464i092F1711A7B22990%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20alt%3D%22clipboard_image_3.png%22%20title%3D%22clipboard_image_3.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EGoing%20back%20to%20my%20history%2C%20you%20can%20see%20everything%20is%20now%20back%20to%20how%20it%20was%3A%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F155465i69A12F2173323BBC%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20alt%3D%22clipboard_image_4.png%22%20title%3D%22clipboard_image_4.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHope%20this%20helps%3B%20if%20so%2C%20please%20mark%20as%20answer.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECheers%2C%3C%2FP%3E%3CP%3EJeff%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Occasional Visitor
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
Highlighted

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