为什么git delete忽略`directory / *`下的文件而不是`directory /`下的文件


this post所述

To put it another way, if you have the following in your .gitignore:

/my-ignored-directory/*

Then you’re screwed – after a git stash save -u, my-ignored-file.txt
will be gone (and sorry, it’s not in the stash you just created
either). Break out the undelete packages and hope for the best.
Alternatively, if you have the following in your .gitignore:

/my-ignored-directory

Then you’re golden – no worries, kick back, relax, my-ignored-file.txt
will stay exactly where it was prior to the git stash save -u.

为什么会有这种差异?我也想知道如果在我的.gitignore文件中我有/ my-ignored-directory /(带有斜杠),是否会删除任何文件?

最佳答案 你们两个例子的结果都是一样的,被忽略的文件都没了.当然有文档中描述的解决方案:

If the –include-untracked option is used, all untracked files are also stashed and then cleaned up with git clean, leaving the working directory in a very clean state. If the –all option is used instead then the ignored files are stashed and cleaned in addition to the untracked files.

Git内部调用git clean -d将工作目录置于非常干净的状态.

你想要的命令是:

git stash --include-untracked --all 
点赞