What's the difference between git reset file and git checkout file?

Why is it that git allows me to reset a file? I thought I understood reset, in the sense that it was moving the HEAD … clearly I was wrong.

So, git reset sha file seems to do the same as git checkout sha file, with the exception that I see file in the index and in the working directory.

  • GIT: Checkout to other branch without doing a commit or stage the files in the first branch
  • How do I use git to checkout just the files and their parent folders that have a given file extension?
  • Are there different meanings to the concept of 'tracking' in git?
  • Should Git workspace automatically adjust to the content of a specific branch?
  • Reducing the size of the .svn folder
  • Does the folder I am in have any significance in git?
  • It doesn’t make sense to me. Can someone please explain the difference?

  • How to get changes to files in a git repo while omitting new files
  • How to rename a git repository?
  • Is there a way to get Tag objects instead of Reference ones when listing tags from a repository?
  • Unstaging changed file from commit in PR
  • Start with a clean slate
  • Using forked Symfony bundle via composer fails
  • 2 Solutions collect form web for “What's the difference between git reset file and git checkout file?”

    git reset has very important flags of --soft, --hard and --mixed ( and --keep and --merge )


    --mixed is the default and when you do git reset sha file you are doing mixed reset whereby:


    Resets the index but not the working tree (i.e., the changed files
    are preserved but not marked for commit) and reports what has not been
    updated. This is the default action.

    Like it says above, the reset in this case would not touch your working tree at all and only the version in the index is reset to the one in the sha.

    git checkout on the other hand:

    When or –patch are given, git checkout does not switch
    branches. It updates the named paths in the working tree from the
    index file or from a named (most often a commit).

    So when you do git checkout you will lose the changes in the file and it will be replaced with whatever was there in the version of file in sha, whereas when you do the mixed reset, only your index will be reset and your working directory will still have the changes which you can later stage again as needed.

    git checkout

    Reverts changes to the file.

    git reset

    Removes the file from the staging area, but keeps the changes.

    Git Baby is a git and github fan, let's start git clone.