有时我发现自己处于我想要在工作树中转储所有内容的位置,除了1或2个文件.是否有捷径可寻?因为它是我手动输入git checkout ....对于我想要从索引中检出的所有文件,并且不包括我想要保留的文件,但这非常费力.
我想到这样做的另一种方法是存储我要保留的1或2个文件,然后"结帐".然后恢复藏匿.这是一个很好的方法吗?
我想偶尔做同样的事情,并且通常使用以下命令集(假设索引中没有任何内容):
git add file-to-preserve-1 file-to-preserve-2
git stash save --keep-index "Changes discarded because ..."
# git stash drop # think twice before running this command
git reset
Run Code Online (Sandbox Code Playgroud)
用语言:
我能想到的另一种方式(实际上没有尝试过,第一种方式适合我):
git update-index --skip-worktree file-to-preserve-1 file-to-preserve-2
git checkout .
git update-index --no-skip-worktree file-to-preserve-1 file-to-preserve-2
Run Code Online (Sandbox Code Playgroud)
解释:
1再次照常处理文件.