Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Development Tools Introduction to Git Managing Committed Files Unstaging Changes

Git command to move stagged files

In the example he uses git reset HEAD medals.html to remove the file from stagged. Is there any difference if I use this command : git rm --cached medals.html

3 Answers

Diem Pham
Diem Pham
12,277 Points

git reset HEAD --fileName will "reset" the index to the state it was before you started adding files / adding modifications to the index.

git rm will remove a file from the working directory and the index and when you commit, the file is removed from the tree as well.

git rm --cached removes the file from index alone and keeps it in your working copy.

I found the answer on stackoverflow - https://stackoverflow.com/questions/5798930/git-rm-cached-x-vs-git-reset-head-x

danielperez
seal-mask
.a{fill-rule:evenodd;}techdegree
danielperez
Full Stack JavaScript Techdegree Student 15,993 Points

The main reason git reset is used is that to remove committed changes

  • the changes may be more than a few lines of code
  • a file that is lot more complex than the little html files in this lesson

in the case of large project knowing how to remove or reset a file back to the state before we committed changes in a life-saver.

I don't get the message to use git reset HEAD, it tells me instead to use git checkout <file>