How to revert a commit on remote #code #programming #tips

preview_player
Показать описание
Learn how to undo a commit in your Git repository in this tutorial. If you've just pushed a commit and need to revert it, follow these steps: first, revert the commit locally using git reset HEAD~1, which will move you behind your last commit on GitHub.

This will make your local repository out of sync, so when you try to push, you'll encounter an error. To resolve this, use git push --force to update the remote branch and remove the last commit from both your local and remote branches. Master the art of managing your commits with ease!
Рекомендации по теме
Комментарии
Автор

I think this info should also come with the knowledge of the consequences of force pushing. The safer alternative is to make a revert commit using just 'git revert <hash> and then push normally.

ethanh
Автор

It's all about that --force-with-lease, my friend

smigit
Автор

Sometimes uncommit is better for version integrity where it shows a commit was reversed on purpose for some reason

EzDoesntExist
Автор

In that scenario its ok, using force you are rewriting history which is a dangerous operation. So yea, for the very last commit only, its ok 😊

AltaiiSinan
Автор

Don’t do this. Use revert instead so that you keep your original git history. It’s much safer too

isaiah
Автор

Terrible advice

Instead revert the commit with git revert.

adrianmazaev