Git:检出除上的所有文件

当我执行git status时,会看到如下文件:

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

我想要做的是放弃对dir / C / file.txt以外的所有文件的更改

我想做这样的事情:

git checkout -- dir/!C/file.txt
Kyle asked 2020-01-29T01:47:00Z
1个解决方案
94 votes
git add dir/C/file.txt # this file will stay modified and staged
git checkout .

如果之后要取消暂存文件:

git reset
mechanicalfish answered 2020-01-29T01:47:11Z
translate from https://stackoverflow.com:/questions/20008025/git-checkout-all-files-except-one