Finding what is lost: Reviewing old commits

The whole idea behind any version control system is to store "safe" copies of a project so that you never have to worry about irreparably breaking your code base. Once you've built up a project history of commits, you can review and revisit any commit in the history. One of the best utilities for reviewing the history of a Git repository is the git log command.

git log -5 --oneline

Each commit has a unique SHA-1 identifying hash. These IDs are used to travel through the committed timeline and revisit commits.

When you have found a commit reference to the point in history you want to visit, you can utilize the git checkout command to visit that commit. git checkout is an easy way to "load" any of these saved snapshots onto your development machine. During the normal course of development, the HEAD usually points to master or some other local branch, but when you check out a previous commit, HEAD no longer points to a branch, it points directly to a commit. This is called a "detached HEAD" state.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/3651a8b6-d3b2-4a9d-a218-52dbd1f01ebc/Untitled.png

References