我有一种感觉,我的 git 缓存经常被混淆。我在 Mac 上工作,在终端和 SourceTree 都使用 git。
我添加或修改了一些文件,但我经常注意到,即使是我从未以任何方式修改过的文件也显示为暂存。这已经很混乱了。
然而,更令人困惑的是,经常发布git add .
将所有文件添加到暂存区什么都不做。我已经使用 git 几年了,以前从未有过。
我在这里阅读了关于 SO 的所有帖子,但没有一个为我解决了这个问题。我发现了一个清除 git 缓存的建议,例如:
git rm --cached path/to/file
git commit -m "Repair confused cache"
git add path/to/file
git commit -m "Add file"
这确实暂时解决了问题,但不久之后,事情又开始发生了。
我还看到 git ls-list --cache 两次返回大多数文件,包括它们的哈希码,如下所示,文件可以是 png 图像、代码文件等:
mymbp:source username$ cd MySolution/
mymbp:MySolution username$ git ls-files --stage
100644 a658bb41271a4285977d1074a69f3302ab5cc15e 0 .gitignore
100644 a658bb41271a4285977d1074a69f3302ab5cc15e 0 .gitignore
100644 197079698252f7f85d6b1e3f68582b9cd1a9288b 0 Publishing/GooglePlay/Icons/res/mipmap-hdpi/icon.png
100644 197079698252f7f85d6b1e3f68582b9cd1a9288b 0 Publishing/GooglePlay/Icons/res/mipmap-hdpi/icon.png
100644 f03e22933ff168571cc5efac90fd4a9bbb4e5968 0 Publishing/GooglePlay/Icons/res/mipmap-mdpi/icon.png
100644 f03e22933ff168571cc5efac90fd4a9bbb4e5968 0 Publishing/GooglePlay/Icons/res/mipmap-mdpi/icon.png
100644 9f8a69a800369b1fd37061b46e808c62747115ac 0 Publishing/GooglePlay/Icons/res/mipmap-xhdpi/icon.png
100644 9f8a69a800369b1fd37061b46e808c62747115ac 0 Publishing/GooglePlay/Icons/res/mipmap-xhdpi/icon.png
100644 64c4174f8086fb7788c5ca922fd4411d8f5050ac 0 Publishing/GooglePlay/Icons/res/mipmap-xxhdpi/icon.png
100644 64c4174f8086fb7788c5ca922fd4411d8f5050ac 0 Publishing/GooglePlay/Icons/res/mipmap-xxhdpi/icon.png
100644 97a01523dd3909b8361d96c1ebd69373db33983f 0 Publishing/GooglePlay/Icons/res/mipmap-xxxhdpi/icon.png
100644 97a01523dd3909b8361d96c1ebd69373db33983f 0 Publishing/GooglePlay/Icons/res/mipmap-xxxhdpi/icon.png
100644 ab64f8448c2d2c74564c00f1cd1aca8bf1dbf200 0 Publishing/GooglePlay/Icons/web_hi_res_512.png
100644 ab64f8448c2d2c74564c00f1cd1aca8bf1dbf200 0 Publishing/GooglePlay/Icons/web_hi_res_512.png
更新 1
的输出git config --list --show-origin
是:
dinosmbp:MySolution dinob$ git config --list --show-origin
file:/usr/local/etc/gitconfig credential.helper=osxkeychain
file:/Users/dinob/.gitconfig core.excludesfile=/Users/dinob/.gitignore_global
file:/Users/dinob/.gitconfig user.name=DinoB
file:/Users/dinob/.gitconfig user.email=db@dbsystems.com
file:/Users/dinob/.gitconfig color.ui=true
file:/Users/dinob/.gitconfig color.status.changed=blue normal
file:/Users/dinob/.gitconfig color.status.untracked=red normal
file:/Users/dinob/.gitconfig color.status.added=magenta normal
file:/Users/dinob/.gitconfig color.status.updated=green normal
file:/Users/dinob/.gitconfig color.status.branch=yellow normal bold
file:/Users/dinob/.gitconfig color.status.header=white normal bold
file:/Users/dinob/.gitconfig commit.template=/Users/dinob/.dinosStandardCommitMsg
file:/Users/dinob/.gitconfig diff.tool=meld
file:/Users/dinob/.gitconfig difftool.prompt=false
file:/Users/dinob/.gitconfig difftool.meld.trustexitcode=true
file:/Users/dinob/.gitconfig difftool.meld.cmd=open -W -a Meld --args "$LOCAL" "$REMOTE"
file:/Users/dinob/.gitconfig merge.tool=meld
file:/Users/dinob/.gitconfig mergetool.prompt=false
file:/Users/dinob/.gitconfig mergetool.meld.trustexitcode=true
file:/Users/dinob/.gitconfig mergetool.meld.cmd=open -W -a Meld --args --auto-merge "$LOCAL" "$BASE" "$REMOTE" --output="$MERGED"
file:/Users/dinob/.gitconfig difftool.sourcetree.cmd=/Applications/Meld.app/Contents/MacOS/Meld "$LOCAL" "$REMOTE"
file:/Users/dinob/.gitconfig difftool.sourcetree.path=
file:/Users/dinob/.gitconfig mergetool.sourcetree.cmd=/Applications/Meld.app/Contents/MacOS/Meld "$LOCAL" "$BASE" "$REMOTE" --auto-merge --output="$MERGED"
file:/Users/dinob/.gitconfig mergetool.sourcetree.trustexitcode=true
file:.git/config core.repositoryformatversion=0
file:.git/config core.filemode=true
file:.git/config core.bare=false
file:.git/config core.logallrefupdates=true
file:.git/config core.ignorecase=true
file:.git/config core.precomposeunicode=true
file:.git/config remote.origin.url=https://github.com/DBSystems/MySolution.git
file:.git/config remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
file:.git/config branch.develop.remote=origin
file:.git/config branch.develop.merge=refs/heads/develop
dinosmbp:MySolution dinob$
更新 2
如果我尝试暂存一个拒绝从 SourceTree 暂存的文件,我会在 SourceTree 中短暂忙碌的微调器(它告诉我它正在尝试暂存它),但随后它消失并且没有任何反应,文件保持未暂存状态。
git add path/file
如果我尝试通过发出or来暂存拒绝从 git 终端暂存的git add .
文件,则不会发生任何事情并且文件不会暂存
更新 3
下面的输出git ls-files --stage | hexdump -C
显示了文件 IoC.cs 的两个不同 SHA 值,该文件当前拒绝使用git add .
命令添加到阶段:
0002ae90 63 73 0a 31 30 30 36 34 34 20 65 37 32 64 31 30 |cs.100644 e72d10|
0002aea0 63 34 31 65 66 31 37 36 64 31 63 35 62 63 66 30 |c41ef176d1c5bcf0|
0002aeb0 62 36 34 63 30 32 36 34 62 32 66 63 65 65 36 65 |b64c0264b2fcee6e|
0002aec0 31 62 20 30 09 53 71 75 69 72 72 65 6c 46 6f 48 |1b 0.SquirrelFoH|
0002aed0 2f 53 71 75 69 72 72 65 6c 2e 46 6f 48 2e 56 69 |/Squirrel.FoH.Vi|
0002aee0 65 77 4d 6f 64 65 6c 73 2f 49 6f 43 2f 49 6f 43 |ewModels/IoC/IoC|
0002aef0 2e 63 73 0a 31 30 30 36 34 34 20 32 62 31 39 61 |.cs.100644 2b19a|
0002af00 36 39 33 35 39 32 66 36 64 32 31 30 38 36 38 33 |693592f6d2108683|
0002af10 63 39 31 62 61 61 30 30 62 64 62 61 62 30 63 34 |c91baa00bdbab0c4|
0002af20 31 31 61 20 30 09 53 71 75 69 72 72 65 6c 46 6f |11a 0.SquirrelFo|
0002af30 48 2f 53 71 75 69 72 72 65 6c 2e 46 6f 48 2e 56 |H/Squirrel.FoH.V|
0002af40 69 65 77 4d 6f 64 65 6c 73 2f 49 6f 43 2f 49 6f |iewModels/IoC/Io|
0002af50 43 2e 63 73 0a 31 30 30 36 34 34 20 37 38 39 64 |C.cs.100644 789d|