Git: Checkout all files except one

2020-05-18 04:09发布

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

1条回答
我想做一个坏孩纸
2楼-- · 2020-05-18 05:01
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
查看更多
登录 后发表回答