Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Introduction to Git!
You have completed Introduction to Git!
Preview
Accidentally deleted a file? Git can get it back for you!
- Suppose we accidentally deleted a file from our working directory that we actually wanted to keep, like our main site page:
rm medals.html
- Git makes it pretty easy to recover the file.
- As before, let's run
git status, and it will show the deleted file:
$ git status
# On branch master
# Changes not staged for commit:
# (use "git add/rm <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# deleted: medals.html
#
no changes added to commit (use "git add" and/or "git commit -a")
- Also as before, there's a message saying
use "git checkout -- <file>..." to discard changes in working directory. - This is similar to using
git checkoutto discard modifications to a file's contents. But in this case, the change we want to discard is the deletion of the file - we want to bring the file back. - If we run that command:
git checkout -- medals.html, the file, and all its contents will be restored.
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
actually wanted to keep,
like our main site page, rm medals.html.
0:00
We can confirm with the ls command
medals.html is now gone from the working
0:01
directory.
0:05
But there's no need to panic, this sort
of thing is the reason we're using git.
0:06
In fact it'll be pretty
easy to recover the file.
0:11
As before, let's run git status,
and it will show the deleted file.
0:13
Also as before, there's a message
saying use git checkout and
0:19
a filename to discard changes
in the working directory.
0:23
This is similar to using git checkout
to discard modifications to a file's
0:27
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