ChatGPT解决这个技术问题 Extra ChatGPT

Git: Checkout all files except one

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

m
mechanicalfish
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

ABSOLUTELY BRILLIANT
git clean -df - is helpful if you have a dirty folder