If you pushed something bad and your teammates are already building on it do the polite thing and revert instead of rewriting public history. git revert creates a new commit that undoes an earlier commit while keeping the project history intact and audit friendly. That means no surprise force pushes and fewer angry Slack messages.
First locate the commit hash you want to undo. A concise log helps you avoid guessing games and blame by committee.
git log --oneline
Copy the short hash for the offending commit. If you prefer a visual history use your GUI client but the CLI is faster when caffeine is low.
To create a new commit that undoes the change run this.
git revert <commit-hash>
If you need to revert multiple commits you can supply a range or revert them one by one.
git revert <start-hash>..<end-hash>
If you want to stage a combined set of undo changes and edit the result before committing use the no commit flag.
git revert --no-commit <start-hash>..<end-hash>
Reverting a merge commit is a bit special. Tell git which parent to keep with the parent number flag.
git revert -m 1 <merge-commit-hash>
If conflicts appear treat them like mild paperwork. Open the conflicted files fix the content to the desired state then stage and finish.
git add <file>
git commit # only needed when you used --no-commit or to finish manual edits
Use git status and git diff to see what is happening. Conflicts are not personal and will not be invited to Thanksgiving.
Once the revert commit exists push it to the remote so the team gets the correction.
git push
This keeps the branch linear and auditable which is exactly what future you will thank present you for.
There you go. Revert when you need to correct public history and keep your repo sensible. If you are cleaning up local mistakes use reset or rebase depending on how tidy you want the log to look. Now go fix that bug and try not to break anything else this week.
I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!
This is a dedicated watch page for a single video.