82

When I do a git status, I see files like this:

modified:  dir/A/file.txt
modified:  dir/B/file.txt
modified:  dir/C/file.txt
modified:  dir/D/file.txt

What I want to do is to discard changes to all files EXCEPT for dir/C/file.txt

I want to do something like this:

git checkout -- dir/!C/file.txt
mavis
  • 3,100
  • 3
  • 24
  • 32
Kyle
  • 3,775
  • 6
  • 37
  • 47

1 Answers1

156
git add dir/C/file.txt # this file will stay modified and staged
git checkout .

If you want to unstage the file after that:

git reset
mechanicalfish
  • 12,696
  • 3
  • 46
  • 41