git add wont stage files - git cache confused?
Asked Answered
M

0

0

I have a feeling my git cache is getting confused fairly often. I work on Mac and use both git at terminal and SourceTree.

I add or modify few files but I often notice that even files I have never modified in any way show as staged. This is very confusing already.

However, even more confusing is that often issuing git add . to add all of the files to staging area does nothing. I have been using git for few years and have never had this before.

I read all posts here on SO and none of them resolved this issue for me. I found one suggestion to clear git cache like:

git rm --cached path/to/file
git commit -m "Repair confused cache"
git add path/to/file
git commit -m "Add file"

This did resolve the issue temporarily but soon after, the thing starts happening again.

I am also seeing that git ls-list --cache returns most of the files twice, including their hash codes which are identical like below and the files can be png images, code files etc:

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

UPDATE 1

The output of git config --list --show-origin is:

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    [email protected]
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$ 

UPDATE 2

If I try to stage a file that refuses to be staged from SourceTree, I get briefly busy spinner in SourceTree (which tells me it is trying to stage it), but then it goes away and nothing happens, the file stays unstaged.

If I try to stage a file that refuses to be staged from git terminal by issuing git add path/file or git add . , nothing happens and file is not staged

UPDATE 3

Output of git ls-files --stage | hexdump -C below shows two different SHA values for file IoC.cs which is currently refusing to be added to stage using git add . command:

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|
Madonna answered 2/1, 2019 at 6:11 Comment(10)
You're on a Mac? Someone else had the same issue on a Mac. As far as I know it was never properly resolved.Cinerama
It's normal to have added a file and then made changes to a file and to have the file both modified and staged.Continence
What's the output of git config --list --show-origin?Linlithgow
@EdwardThomson I added it in the UPDATE section. Thank youMadonna
The other user who had the same issue has an open question here. This sure looks like a (MacOS-specific?) bug in Git.Cinerama
yes, that is the same issue actually. Less likely MacOS specific Git bug since no other Mac or Win users are seeing it here. Only this one Mac machineMadonna
Very odd - I wonder if there's some nonprintable characters in those filenames. Could you git ls-files --stage | hexdump -C?Linlithgow
@EdwardThomson I added the output in UPDATE 3 section above. The output shows only part relating to IoC.cs file which currently wont get staged if I issue git add . command. You can see it shows up 2ice in the output with 2 different SHA values, first starting with e72d10 and 2nd starting with 2b19a. Does this give you any clues? ThanksMadonna
@EdwardThomson ... I would also like to add that this is not happening on Windows. I just backed up my project with my feature branch, copied it to Windows machine and then copied from it file-by-file my changes to a brand new clone/feature branch, and I was able to stage, commit, and push without any issues. On Mac however, I run constantly into the issues I described above including this one #54084419 which I believe is side effect of the above described...Madonna
@EdwardThomson ... We are crossplatform team and 2 of us use Mac but only I have the issue; others, are on Windows. Could it be line endings or something else and how to find out? Much appreciatedMadonna

© 2022 - 2024 — McMap. All rights reserved.