Checkout commit
- To view complete snapshot of the project at a point in time, checkout the commit
- Restore the working directory to the snapshot stored in that commit
git checkout commit
- When you checkout, the repo is in detached head state
- Each commit points to the previous commit, using this git maintains history
- You can have multiple branches in git
- Every git has a default branch called
master
(trunk)
- Way git represents a branch is using a pointer
master
is pointing to the last commit
- As we create new commit master moves forward to point to the last commit
- Because we can have multiple branches. git need to know what is the branch we are currently working on
git uses another pointer called
head
.
head
points to the current branch we are working on
- As we create new commit head and master pointer moves forward to point to the last commit
- When we checkout a particular commit, head pointer moves to that commit. this is called detached head. head is not attached to branch anymore
- We shouldn't create new commits only view our code
- if you create new commit, it will not be reachable by any other commit and it will become dead commit
- git checks periodically for dead commit, removes it to save space
To attach the head pointer to the master branch
git log --oneline
git log --oneline --all
git checkout master