What are the steps to do code rollback in master branch?

Viewed 22

I am using azure devops pipeline, I need to do a code rollback in my master branch,(the code in the master branch is coming from different release, e.g release/1.0.0, release/1.0.1 and tagged.)

From what I have searched, I got the following:

    1. git checkout master
    2. git reset --hard <tagname>
    3. git push --force origin master

Can anyone help, is this the best way of doing a rollback in a master branch ? OR not. Also, in this case the code will be overwritten with previous tags code, do we need to tag the branch again.

1 Answers

Sounds like a big step to me.... do you know the consequences of rewriting history that way? If you don't then probably this is not the right path. Normally, if you want to take code back to how it was back in a revision, you should create a new revision following current history that takes code back.

In your case, you should do something like:

git checkout --detach <tagname>
git reset --soft master # set the HEAD pointer where master is
# content of files in working tree and index are like in <tagname>
git commit -m "Take code back to <tagname>"
# at this point this is a revision with no branch
# check history with git log to see if this is what you would like to have in master
# if you do like it:
git branch -f master # set master branch over here
git checkout master
git push

That should work.

Related