Using git, how do you reset a running tree in index state?

Situation:

  • Edit files
  • Add files to index
  • Edit more files

Now we have three different states. HEAD state, index state, and working tree state. Which command cancels changes in the working tree so that it matches the state of the index?

+43
git
Jun 24 '10 at 6:54
source share
4 answers

I am using git checkout . which discards all changes from the working directory. It matters if you are not at the root of the repository.

This command does not delete newly created files, which is usually good. If you need to do this, you can also use git clean .

+49
Jun 24 '10 at 7:10
source share

You can use git stash save --keep-index for this. After storing the cache, you can use git stash drop if you do not want to support it.

+14
Jun 24 '10 at 7:07
source share

You can use git-checkout-index . Keep in mind that you need to add

  • -f to force it to overwrite existing files or
  • -f -a to overwrite all paths in the index.
+8
Jun 24 '10 at 7:01
source share

git checkout :/ discards all changes in the working tree and replaces it with the one in the index, regardless of the current working directory.

https://git-scm.com/docs/gitglossary#gitglossary-aiddefpathspecapathspec

0
Nov 28 '17 at 19:30
source share



All Articles