Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Development Tools Introduction to Git Managing Committed Files Undoing File Deletions

Is the Git Command the Same for Discarding a File "AND" Retrieving a Discarded File?

The tutorials illustrated that the command git checkout -- filename.extension is used to both Discard a File and Retrieve a Discarded File.

I believe this command works as illustrated, but I would like to ascertain that this is indeed an accurate description.

1 Answer

Jay McGavren
STAFF
Jay McGavren
Treehouse Teacher

The best way to describe git checkout -- filename is that it retrieves a file as it existed in your last commit. If you've deleted the file, it brings the file back. If you've changed the file, it changes the file contents back to the way it looked as of the last commit.

git checkout -- filename doesn't discard a file. (That's what git rm is for.) git checkout -- filename discards changes to a file.

If youve never commited the file for whatever reason. You start working on it and accidently delete the file youve never commited is it gone now?