Git fundamentals
Theory: Moving through history
Git allows you not only to view the history, but also to navigate through it by uploading the state of the code to the working directory at the time of any commit. Let's have a look:
Let's switch to the moment when the commit with the add INFO.md message was executed. To do this, use the git checkout <commit hash> command:
Run the command above (your commit hash may be different) and examine the working directory. You will see that some of the changes are missing since we're going back in time. The changes themselves have not gone anywhere, and we can go back to the last commit again with the next command:
By switching to the desired commit, you can not only explore the contents of the repository, but also pick up any changes that were deleted but are needed again for work. To do this, just copy them, switch to the last commit, and paste them into the desired file.
Where am I
Switching between different commits only affects the contents of the working directory. Where we are is not visible anywhere else. Because of this, quite a few programmers forget where they are and start working and, as a result, are very surprised when they can't get a commit done.
The easiest way to find out your position is to call the git branch command. Normally, when we are on the last commit, git will show this output:
But if a commit from the past is loaded right now, the output will be this:
This way of checking your current position requires constant attention. You have to remember to use it and, of course, everyone forgets to. It is much more reliable and convenient to display the current position directly on the command line. For example, like this:
That's what most professional developers do. How do you achieve that output? The answer to this question depends on the shell used. In Bash, you can display position in prompt line by editing the $PS1 environment variable, you can read more about this by following the link in the additional resources.

