haydenmuhl haydenmuhl - 11 months ago 107
Git Question

Using git, how do you reset the working tree to the state of the index?

Situation:


  1. Edit files

  2. Add files to the index

  3. Edit more files



Now we have three different states. The state of HEAD, the state of the index and the state of the working tree. What is the command to undo changes in the working tree so that it matches the state of the index?

Answer Source

I tend to use git checkout . which discards all changes from the working directory down. This makes a difference if you're not at the root of the repository.

This command doesn't remove newly created files which is usually a good thing. If you need to do this then you can use git clean as well.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download