Home > Blockchain >  Git loses tracking randomly
Git loses tracking randomly

Time:05-31

I have a problem for two weeks with git, more precisely with git for windows (Git-2.36.1-64).

This is very strange behaviour, cause randomly (for me it's randomly) git loses tracking of files. What I mean, that I modify 10 files, and when I commit, it will commit 7 files, but forgets 3 another files. Then I have to run two commands: "git rm --cached . -r" and "git reset ." and this commands always help me. Sometimes it keeps all files for 2 hours, sometimes forgets all files. "git status" command shows that repo is clean, nothing is in stage or unstage mode. Even I modify file... Sometimes it keep files, sometimes not. It is not problem with console, VS Code or Visual Studio same problem, just loses tracking.

Unfortunately, this happens with all repositories. Reinstalling git or using git portable did not help. I also used "Reset PC" in Windows but keep my files, it removed env variables etc. Also did not help.

I am 100% sure that those repos are ok, cause my collegues use the same repos from our Azure DevOps. I also used this repos on my second computer and never had problem like this.

I am run out of ideas and this is very disturb my daily work...

About Windows, I am using newest version of Windows 11. Maybe this is the problem?

EDIT: Today it happened again, so I can show what is happening. File being modified but not saved yet Filed saved and dissapered from changes Git status also shows working tree clean Run Git rm --cached . -r and git reset . Now git tracks the file

  1. File being modified but not saved yet
  1. Filed saved and dissapered from changes
  1. Git status also shows working tree clean
  1. Run Git rm --cached . -r and git reset .
  1. Now git tracks the file

CodePudding user response:

[edit] This answer first suggested an issue with a file syncing service, but after further debugging, it looks like your issue linked to some flags set in your local repository :

running git ls-files --debug | grep -B5 "flags: [^0]" you established that some files had the assume-unchanged flag set (displayed as flags: 8000).

You can read the Using assume unchanged bit section of git help update-index for more details (or for a good headache ;) ),

Here is the command to remove that flag from one individual file :

git update-index --no-assume-unchanged <filepath>

There is a shorter way to get the complete list of assume-unchanged files :

git ls-files -v | grep "^[a-z]"   # see the doc: status is lowercase if assume-unchanged

# to "un assume unchange" all files in one go :
git ls-files -v | grep "^[a-z]" | awk '{ print $2 }' |\
    xargs git update-index --no-assume-unchanged

Also check the core.ignorestat config value: it should be set to false (or you should be aware of a good reason to keep it to true)

git config core.ignorestat

Some other configuration variables affect how git deals with its index, they all start with core. (read git help update-index and search for core. to list them) :

git config --show-origin --get-regexp core

# config variables to look for (2022-05-31 - git version 2.35.0) :
#   core.filemode
#   core.fsmonitor
#   core.ignorestat
#   core.splitIndex
#   core.symlinks
#   core.trustctime
#   core.untrackedCache
  • Related