ignoring_gravity
ignoring_gravity

Reputation: 10573

`git checkout` not resetting file

Here's my situation. I'm on branch my_branch, have accidentally modified a file (and have staged these changes), and would like to reset this file to how it was on master. However, if I doing so using git checkout, I get an error (see below for details).

$ git branch
* my_branch
  master

$ git fetch origin master
From [MY REMOTE]
 * branch            master     -> FETCH_HEAD

$ git status
modified:   my_folder/my_file.py

$ git checkout origin/master -- my_folder/my_file.py
error: pathspec 'my_folder/my_file.py' did not match any file(s) known to git.

How should I be using git checkout? What might be causing git to list this file as 'modified' in git status, but to say it's not recognised during git checkout?

Upvotes: 2

Views: 752

Answers (1)

w1sh
w1sh

Reputation: 68

If you've modified the file locally and staged it you need to do git restore --staged my_folder/my_file.py to unstage that file.

After the file is no longer staged you can do git restore my_folder/my_file.py to discard all changes.

Upvotes: 2

Related Questions