Git Revert multiple commits at a time — Technolize Your Future
2 min readOct 23, 2020
In this article, we will see how Git Revert multiple commits at a time without affecting/changing the Git history.
You must have reverted a single git commit at one point in time during programming. Also must have faced a problem where wanted to revert multiple Git commits at a time so let’s see how to do that.
- In general, one should not rewrite/change the Git history because if you are working in a team then somebody else might have work on some feature based on your commit.
- And, If you change the Git history then you would make it a problem with merging their changes and with updating the code for them.
- So the simple and easiest way to revert multiple Git commits is by following the below process:
// Below is based on the commits where top most commit is commit id: commit-id-5 and the bottom one is: commit-id-1
// So if you want to revert the top 4 commits that is commit Ids:
// commit-id-5, commit-id-4, commit-id-3, commit-id-2
// then you can do below.
git revert --no-commit commit-id-5
git revert --no-commit commit-id-4
git revert --no-commit commit-id-3
git revert --no-commit commit-id-2
git commit -m "the commit message"// and then push your code.
// Above process will create a new commit which will have all the changes as reverted code from mentioned commit Ids.
Visit https://techtalkbook.com to find more related topics.
Happy Coding!!!
Originally published at https://techtalkbook.com on October 23, 2020.