为什么 git stash 使我的工作目录处于脏状态?

Why is git stash leaving my working directory in a dirty state?

$ git add -A

$ git status 
... 
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        modified:   Source/ConfigGeneratorTests/ConfigGeneratorTests.csproj
        (and 20 other files) 

$ git stash save
Saved working directory and index state WIP on ...

$ git status 
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   Source/ConfigGeneratorTests/ConfigGeneratorTests.csproj
        (and 20 other files) 

stash save 之后,添加到索引中的文件现在不会隐藏,也不会保存在索引中。是否有一个原因?我用过 stash 很多次,但从未见过它这样做。

我不确定这是否真的是你的情况,但最近在我的同事有将 .gitattributes 文件推送到 github,其中行尾设置已更改(例如从 as-is 签出 windows 风格,提交 linux 风格 ).

所以 git stash 没有产生任何错误,但同时没有产生任何效果(修改后的文件出现在状态中,并一直停留在那里,直到我提交它们)。删除 .git 属性 对我有用。

我刚刚遇到 git stash 未能留下干净的工作目录的另一个原因:我正在通过 samba 安装访问我的 git 存储库。

一堆文件突然设置了执行权限,这显示出不同。 git stashgit reset --hard都无法恢复权限,可能是因为正在进行samba安装的客户端机器实际上无法影响权限。

登录到服务器并直接在其本机文件系统上访问 git 存储库使问题消失。