Git stash会把修改过的文件放到哪里?

9
我在尝试隐藏更改时遇到了一些奇怪的行为。我不是一个git专家,所以希望有人能够解释一下:
  1. 在最新的分支上,我修改了一个已跟踪的文件。git status显示它已被修改
  2. git stash(回应“Saved working directory and index state WIP on...”)
  3. git status仍然显示该文件已被修改,但git diff(和git gui)没有显示任何更改。
  4. git stash list显示已创建了隐藏
  5. git stash pop 回应“error: Your local changes to the following files would be overwritten by the merge:”

第3个行为对我来说毫无意义。它最近才开始发生。我已经使用stash/stash pop几个月了,没有问题。

我想知道是否存在本地工作副本问题,因此我重新克隆了一份,但出现了相同的行为。

我的GIT安装有问题,还是我漏掉了什么?

额外信息:

  • 在另一台PC上尝试过,表现如预期,因此与此安装有关。

  • 尝试创建一个新的本地repo,添加&提交1个文件,修改,隐藏。相同的行为

  • 尝试使用CR LF和LF行结尾的文件。相同的行为

git config -l:

core.symlinks=true
core.autocrlf=true
core.fscache=true
color.diff=auto
color.status=auto
color.branch=auto
color.interactive=true
help.format=html
diff.astextplain.textconv=astextplain
rebase.autosquash=true
http.sslcainfo=C:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt
http.sslbackend=openssl
diff.astextplain.textconv=astextplain
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
credential.helper=manager
core.editor='C:\Program Files (x86)\Notepad++\notepad++.exe' -multiInst -    notabbar -nosession -noPlugin
core.excludesfile=C:\GIT\gitignore\VisualStudio.gitignore
core.editor=notepad
core.fscache=true
core.preloadindex=true
gui.fontdiff=-family Consolas -size 10 -weight normal -slant roman -    underline 0 -overstrike 0
gui.recentrepo=C:/GIT/polarisv4
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
user.name=xxxxx
user.email=xxxxxx
difftool.sourcetree.cmd='C:/Program     Files/TortoiseGit/bin/TortoiseGitMerge.exe' "$LOCAL" "$REMOTE"
mergetool.sourcetree.cmd='C:/Program     Files/TortoiseGit/bin/TortoiseGitMerge.exe'  -base:"$BASE" -mine:"$LOCAL" -    theirs:"$REMOTE" -merged:"$MERGED"
mergetool.sourcetree.trustexitcode=true
alias.co=checkout
alias.br=branch
alias.st=status
winupdater.recentlyseenversion=2.15.1.windows.2
credential.helper=manager
core.repositoryformatversion=0
core.filemode=false
core.bare=false
core.logallrefupdates=true
core.ignorecase=true

你能在一个新的代码库(从头开始创建)上重现这个问题吗?还是只有在这个特定的代码库中才会出现这个问题? - Ortomala Lokni
你已经尝试过 git stash clear 了吗?请注意,这些条目将受到修剪的影响,可能无法恢复。在使用 git stash list 命令之前,请先检查它们。 - Ortomala Lokni
1
git stash 在做完两个提交(索引和工作树)后运行 git reset --hard。如果 git reset --hard 使工作树处于修改状态,那么你将会得到这种情况。在某些 CRLF 转换设置下,它确实会这样做,例如当存储在仓库中的文件是只读的,并且具有与当前配置不兼容的行结尾时,现在也在索引中。 - torek
@torek 如果我理解正确的话,一旦我处于这种状态,git reset --hard 就不会有任何作用?但是如果我执行它,实际上我会回到一个干净的工作树。 - DaveW
1
@DaveW 试着暂时移除所有全局 git 配置文件:https://www.onwebsecurity.com/configuration/git-on-windows-location-of-global-configuration-file.html - Ortomala Lokni
显示剩余4条评论
2个回答

3
正如DaveW所说,问题源于core.fscache=true设置。这是一个仅适用于Windows的设置,它启用了一个文件系统缓存,以缓解某些Windows文件系统操作的速度较慢的问题。以下是从提交消息Win32: add a cache below mingw's lstat and dirent implementations中提取的描述:
“在Windows上检查工作树状态非常缓慢,原因是lstat模拟(Git针对索引中的每个文件调用一次lstat)缓慢。Windows操作系统API似乎比检查单个文件更擅长扫描整个目录的状态。添加一个使用lstat数据缓存的lstat实现。缓存未命中会读取整个父目录并将其添加到缓存中。对于同一目录的后续lstat调用将直接从缓存中提供服务。还实现了opendir/readdir/closedir,使它们在缓存中创建和使用目录列表。”
此提交消息的最后一句话说明了OP问题的原因。

有道理。感谢提供额外的背景信息。 - DaveW

2

在Ortomala Lokni的建议下,我删除了所有全局git配置文件1

问题得到了解决。我逐个重新安装每个文件,直到问题再次出现,然后调整了一些看起来合理的设置。

罪魁祸首是fscache - 将其设置为true会导致问题。我不知道为什么,因为相同的设置在其他电脑上运行良好。

感谢大家的帮助!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接