Skip to Content
Learn
How to Backtrack
git checkout

What if you decide to change the ghost’s line in the working directory, but then decide you wanted to discard that change?

You could rewrite the line how it was originally, but what if you forgot the exact wording? The command

git checkout HEAD filename

will restore the file in your working directory to look exactly as it did when you last made a commit.

Here, filename again is the actual name of the file. If the file is named changes.txt, the command would be

git checkout HEAD changes.txt

Instructions

1.

Change the ghost’s words in some way. Here’s a fun suggestion:

Ghost: My hour is almost come, When I to sulphurous and tormenting balloons Must render up myself.
2.

From the terminal, use git diff to see the difference between scene-5.txt as it appears in the working directory vs. how it appears in your last commit.

You may need to press q on your keyboard to restore the terminal.

3.

Use the new Git command to restore the file in your working directory to look as it did when you last made a commit.

Notice that the changes you made to the ghost’s line have been discarded.

Folder Icon

Sign up to start coding

Already have an account?