Once we reset a project to an earlier point, do the commits after that point get deleted?


#1

Question

As we can see in the following image from the git reset review lesson:


once we reset the HEAD, some of our commits seemingly become inaccessible. Are they deleted? Can we access them later if we made a mistake?

Answer

It may indeed happen that we reset to a point incorrectly or we simply realize at a later time that we would like to revisit one of these previous commits. It is correct that these commits are inaccessible from the main branch that we modify but they are not deleted. Git, in a sense, backs these up on our behalf and we can revisit them if needed with the git reflog command. The reflog command is short for reference log and provides just that, a log of the history of our project. From here, we find the SHA-1 hashes for each commit. Therefore, if we would like to reset to that commit or checkout a file from one of these commits we can utilize the hash to access the commit.


FAQ: How to Backtrack - git reset review