Video in progress
A commit has already been pushed to `main` and then turned out to be wrong. Do you remove it with `reset` or with `revert`?
On a shared branch you use git revert: it adds a new commit that applies the opposite of the bad commit and does not rewrite history. reset + force push breaks other people's history.
📖 Answer
This is where people often slip in interviews: "I will reset and force push". That is fine for a personal branch, but not for main. Colleagues may already have built work on top of your commit.
git revert 7c41e9a
# new commit: "Revert "Chegirmani har doim 10% qilish""
git push origin main
The reverted commit stays in the history, and that is good: you can see later what happened.
Reverting several commits:
git revert --no-commit a1b2c3..f6e7d8
git commit -m "Yangi hisobot moduli vaqtincha olib tashlandi"
When reverting a merge commit you need -m 1, to say which parent is the "mainline". The rule is short: not pushed, reset; pushed, revert.
Sign up to mark studied questions and save your progress.