Traveling multiverse of git history
undo git commit
Have you ever made mistake and lost track of your code while working? but even after a bit of google research left confused about what to use between git reset, git revert, or the git checkout.
okay my friend I got your back. let's get into it.

Overview:
git checkout : go to previous commit
git log : fetching history
git revert : undo public changes
git reset : undo local changes
git clean : delete untracked files
Git checkout :
git checkout is a time traveler for your code. you can go back to a certain commit by using that commit hash and check what the code looked like at that time.
you can also travel to different branches using git checkout. It will let you travel the multiverse of git history.
git checkout hash
git checkout branchname
If you have uncommitted changes you can undo them by :
git checkout — — filename
for changes in more than one file, you can run
git checkout — — .
Git log :
Now, you must be wondering how can you find the associated hash with a specific commit. here git log comes into the picture .git log is used for fetching the latest commit info.
Just run the git log in your terminal.
Only need ID and associated commit messages? Use –oneline flag.
git log — oneline
Git Revert :
If you have committed changes you won't be able to use git checkout to undo them .instead you can use git revert.

suppose you want to go back to the previous commit or want to undo a certain commit, you can use :
git revert commit_hash
git revert will be saved in the git history.
Git Reset
If you don't want the changes as well as the history of the code changes. you can use git reset. It is not recommended to use git reset in public repo cause those repos are used by other developers also. resetting commits can rewrite git history which can cause merge conflicts.
Use git reset when you are in your local repo.
git reset — — hard Head~1
this will reset behind one commit.
git clean
You can delete untracked files by using git clean.
git clean -f
Reference:
If you want to read more about the above commands you can check out :
Happy Coding!