Creating a project is like hiking in a forest. Sometimes you take a wrong turn and find yourself lost.
Just like retracing your steps on that hike, Git enables you to rewind to the part before you made the wrong turn. You can do this with:
git reset commit_SHA
This command works by using the first 7 characters of the SHA of a previous commit. For example, if the SHA of the previous commit is
git reset 5d69206
HEAD is now set to that previous commit.
From the terminal, print out your Git commit log.
Note: If your cursor gets stuck in “git log” mode in the terminal, press “q” on your keyboard to escape.
From the terminal, enter the command to
reset to a previous commit, using the first 7 characters of one of the past commit SHAs in your Git log.
Next, print the Git commit log again.
Notice anything interesting? The commits that came after the one you reset to are gone. The
HEAD commit has been reassigned. You just changed history.