← Other topics

Git delete commits and reset code base to a specific commit

Video Notes

The following git steps will reset a code base to a specific commit, deleting all commits made since.

This is not considered git-best-practice as it “rewrites history” by deleting old commits and this can cause issues for collaborators who have pulled the commits you are deleting.

Knowing that, only apply this technique if you are sure that deleting commits is the outcome you want and understand the risks.

For other less destructive ways to revert git history, check out this thread: StackOverflow: How can I revert multiple Git commits?

Command summary

> git log --oneline
> git reset --hard <commit_hash>
> git push --force

Commands with explanations

See git history to get hash of the commit you want to revert to:

> git log --oneline

Reset to the hash of the commit you want to revert to:

> git reset --hard <commit_hash>

The above command:

Push the reset:

> git push --force

The above command:

Unlock all the notes for $4

No subscriptions, no auto-renewals.

Just a simple one-time payment that helps support my free, to-the-point videos without sponsered ads.

Unlocking gets you access to the notes for this video plus all 200+ guides on this site.

Your support is appreciated. Thank you!

Payment Info

/
$4 6 months
$25 forever
Please check the form for errors
Questions? help@codewithsusan.com
← Other topics