Azure Devops Repos - Revert back to a previous commit like the recent ones never existed
Solution 1
Git reset command can achieve this.
You can run the git reset --hard
command to revert back to a previous commit. Then run git push --force
command to wipe out all the commits came after this commit on server.
git clone <repo_url> #clone your azure git repo to local
git checkout <branch>
git reset --hard <commithash> #revert back to a the previous commit
git push --force #push to remote server
After you run above git commands locally. You will see on azure devops git the commits coming after are gone.
Solution 2
While code approach is available, Azure DevOps website provides very quick method.
Go to Azure DevOps -> Your Repository -> Switch to the Working branch where you just made the commit that needs to be changed.
-
Go to History and click on the commit that needs to be reversed.
-
It will automatically create a new branch and will ask you to approve a pull request from this new branch to your working branch. Complete this pull request.
-
Verify that your commit has been reversed in the working branch as expected.
Note: At times if there are multiple dependencies on a commit, it might throw an error. But usually, it works fine.
cbrawl
Updated on June 05, 2022Comments
-
cbrawl almost 2 years
I know that you can revert back to a previous commit but it doesn't sound like the history will be gone. How can I revert back to a previous commit and make sure the commits that came after are gone forever?
-
Levi Lu-MSFT over 3 yearsHi, did you get a chance to try out below answer? How did it go?
-
-
GLP over 2 yearsWorks like a charm in Azure Devop.