Close

Rolling back to an earlier Git commit

Find the git commit you want to rollback to:

Announcement

I have released my new course on Udemy, Kubernetes By Example. Sign up now to get free lifetime access!
git log -n20
git checkout <commit hash>

Then do:

git reset --hard <commit hash>
git push origin HEAD:master --force

Note this can inconvenience some users because they can end up with conflicts since you did a a forced push.

So another approach after checking your commit, is to create a new branch and then create a PR to merge in the rollbacked code:

git checkout -b rollbacked-code
git push # then create a PR