There are several different ways to go back in time with git.
1) git reset
(Josh's answer) will allow you to rollback changes to go to a point in your git history, and pretend as if the later changes had never happened. Thus, it's dangerous, because if you're not careful, you can lose code/changes forever, and mess up your teammates and your team repo pretty badly.
This approach could work if you haven't already pushed your changes (rebased commits) to GitHub, and you're just trying to fix something you did wrong in your local repo.
2) The generally "safer" option is to use git revert
to revert changes in a safe/logged way, where it creates a NEW commit that undoes the changes of a previous commit. That way the whole history of what happened is preserved.
To undo the most recent single commit, git revert HEAD
is usually sufficient
To revert the three most-recent commits, you can do
git revert HEAD HEAD~1 HEAD~2
However, you might also want to use git log
to find the identifiers (long string of unique characters) that identifies the commits that you want to "undo", and do:
git revert id1 id2
Note that you are undoing the changes represented by each commit, not rolling back to the state after that commit!
For more info, read: https://www.freecodecamp.org/news/git-revert-commit-how-to-undo-the-last-commit/