Reset rewrites history: it moves main back past commits. Once a commit is pushed and teammates have pulled it, that breaks their clones. Their main still has the commit, yours doesn't, and the next push or pull goes wrong. Never reset commits that others already have.
git revert undoes a commit the shared-history way. It makes a new commit that applies the opposite change, and leaves every existing commit alone:
git log --oneline
a731028 (HEAD -> main) Add a FAQ
3338d7e Add a banner
c45945c Start the shop
git revert HEAD~1
hint: Waiting for your editor to close the file...Git suggests the message Revert "Add a banner", followed by This reverts commit 3338d7e…. Save it:
[main 3ec7269] Revert "Add a banner"
1 file changed, 1 deletion(-)
git log --oneline
3ec7269 (HEAD -> main) Revert "Add a banner" ← new commit, opposite change
a731028 Add a FAQ ← later work untouched
3338d7e Add a banner
c45945c Start the shopPush it like any commit. git revert --no-edit <commit> takes git's message without opening the editor.
Objectives
- Undo the discount with a new commit.
- Keep the later work.
- Share the fix.