Search code examples
gitgit-reset

What's the status of files when using a git reset --mixed HEAD~1?


For example, if I create a file.txt and add some contents to it and then I commit this change to history. And what's the status of file.txt when using a git reset --mixed HEAD~1? I use the git status to check the status and below is the output:

On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   file.txt

no changes added to commit (use "git add" and/or "git commit -a")

My question is, is this file.txt still in the index(staged)? If yes, why cannot I use git commit to commit the change?


Solution

  • file.txt has been modified compared to the commit you have checked out. The modifications are only present in the working directory. In order to commit them you need to add file.txt to the staging area (or index, same thing) and commit.

    To discard the modification, you can checkout the file, meaning its' content will be synchronized with the content of the file in the commit you checkout.