How to revert a Git repository to a previous commit
There are three common ways. Pick by whether the commits were already pushed.
1. Shared history: git revert
Creates a new commit that undoes an older one. History is kept, so it is safe after pushing.
git revert <commit-hash>
2. Local only: git reset
Moves the current branch back to an older commit.
git reset --soft <commit-hash> # keep changes staged git reset --hard <commit-hash> # discard changes
Warning: --hard throws away uncommitted work. Do not reset commits that others already pulled; if you must, you will need a force push.
3. One file only
git restore --source=<commit-hash> path/to/file
Find the hash with git log --oneline.