Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
Made changes to a file, but want to get the original version back? Git can help!
Update
git restore medals.html
Video Recap
- In the previous video, we staged a change to
medals.html
that added a heading announcing a "100% off sale". We decided that was a bad idea, so we unstaged the change. - But the
medals.html
file saved in our working directory still has that "100% off" heading.
Warning: We're about to show you something Git can't undo. The changes in the medals.html
file have never been committed, so Git doesn't have them stored anywhere. And we're about to erase those changes. When you're discarding changes to a modified file, make absolutely sure you're not discarding changes that you actually wanted to keep!
- If we run the
git status
command, we'll see another helpful hint:use "git checkout -- <file>..." to discard changes in working directory
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: medals.html
- Let's try this command out on the
medals.html
file.
git checkout -- medals.html
This uses some special syntax that is mainly used together with git checkout
- a space, a pair of dashes, and another space: --
. This is not a command line option. An option would be followed by an option name rather than a space. Instead, it's a separator that makes it clear to Git that any arguments that follow will be file names.
- Now, we can run
git diff
again. Since the changes have been discarded, it no longer shows any output. - We can also run
git status
again, and we'll see the working directory is clean. There are no files that have been modified since the last commit, or rather, ourmedals.html
file has been changed back to its state as of the last commit.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up