Detached Head state:
- Use git checkout [commit hash] to jump into that timeline. and you can git switch master to reattach the head. You can also use git checkout Head~1 or Head~2.. where Head~1 refers to the commit before Head and Head~2 refers to 2 commits before Head.

- Normally the Head points to the branch we are in. suppose master. and the master branch to the recent commit.
- When you are in detached head state the master points to the recent commit while the head points to the commit that you checked out.

- You can also make new branches when you switch to a old commit. First use git checkout [commit hash] to switch to that commit and here you can create a all new branch by git switch -c [Branch Name].
Discarding Changes:
- Suppose you have made some changes to a file but dont want to keep them. To revert the file back to whatever it looked like when you last committed, you can use git checkout Head <File> or git checkout — <FIle> (Head always refers to the latest commit).
- Eg: created a file dog.txt . added “first commit” in that file. Now you staged and committed the file. Now you added “ddscdsc” and you staged the file. Now you want to remove that extra line, you can use git checkout Head dog.txt .
Git Restore:(same as ctrl + z)
- git restore <File> is used to undo the changes in the current working file. an alternative to git checkout Head <File>.
- Eg: Open a directory. add some text in the file. Incase if you deleted by mistake you can use this command to restore.
Unstage Files:
- Use git restore —staged <File> to remove the file from staging area.
Git Reset:
- Use git reset <commit-hash> to reset the repo back to a specific commit. It doesnot remove the changes.
- Use git reset —hard <commit> if you want to undo both commits and the actual changes in you files.
Git Revert:
- git revert is similar to git reset in that they both undo changes, but they accomplish in different ways.