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 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

Julie Pham
Julie Pham
12,290 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>