Switch to an old revision and back

Open the project in VS Code:

code ./

Open the config/routes.rb file in VS Code.

Note that the file contains the line: resources :people. This line was added when we added the new person pages.

View the commit log graph:

gloga

Note the hash for the first commit. On my system it is b23bdbd, but on yours, it may be different.

Check out the first commit, using the hash shown by gloga:

git checkout b23bdbd

Note that the routes.rb file has now changed. It no longer shows the resources line, because it is now the version from the first commit. If you inspect the other project files, you will find that they have all been reverted to their original versions.

View the commit log graph:

gloga

Note that the main pointer and the HEAD pointer are now pointing to different commits. main has not moved, but checking out the old commit caused the HEAD pointer to move.

When the HEAD doesn’t point at a branch, it is referred to as a detached HEAD. When the HEAD is detached, you cannot make new commits. You must be “on a branch” to make commits.

Switch back to the main branch:

git switch main

Note that the routes.rb now has the resources line again, and indeed, all the files have been restored to their latest versions.

View the commit log graph:

gloga

Note that the HEAD is no longer detached and now points at main again.


⏴ Back Next ⏵