Git: Checkout all files except one

GitGit Checkout

Git Problem Overview


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

Git Solutions


Solution 1 - Git

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionKyleView Question on Stackoverflow
Solution 1 - GitmechanicalfishView Answer on Stackoverflow