tags:

views:

37

answers:

3

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?

+1  A: 

checkout git-checkout-index. Is this what you are looking for?

Peter Tillemans
This is also good to know about, but not what I was looking for. If I change foo and add foo to the index, then change bar, running this command will not roll back the changes to bar in the working tree.
haydenmuhl
@user374953: You need to use `git checkout-index -f <path>` to force `checkout-index` to overwrite existing files or `git checkout-index -f -a` to do this for all paths in the index.
Charles Bailey
+1  A: 

You can use git stash save --keep-index to do this. After saving the stash, you can use git stash drop if you don't want to keep it around.

Greg Hewgill
+1  A: 

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.

Charles Bailey
Tested these out, and they are what I'm looking for. Thanks.
haydenmuhl