vscode-dev-containers icon indicating copy to clipboard operation
vscode-dev-containers copied to clipboard

Bug - git in container not properly tracking changes

Open joezappie opened this issue 3 years ago • 6 comments

I keep running into an issue with dev containers where its incorrectly tracking changes. Frequently, git will stop detecting that a change has been made. It can happen for an entire branch or a single file. This keeps making me lose code as I'll push a bunch of changes, but didn't realize several files had this bug and didn't get tracked. Very frustrating.

I'm not entirely sure but I think this has something to do with switching branches. Up until recently I was only working on master and never had any issues. I've now switched to using separate branches and I keep running into this issue.

Sometimes git will never catch any changes, sometimes it will only show new untracked files or sometimes random files will not be considered modified, sometimes it works fine.

Sometimes switching between branches, my changes will show up there even though they were not made on that branch.

Here is a video of the bug in action: https://www.youtube.com/watch?v=Y0fXDw-VgCw

I have tried this on several versions of VS Code including the latest insider build.

These files are not in the .gitignore. After switching back to the branch from the video, editing the same file tracks the changes.

This is on a fresh Windows 11 system, reinstalled on a new drive about 3 weeks ago.

  • VSCode Version: 1.69.1 / 1.69.2 / Latest Insider
  • Local OS Version: Windows 11 Pro 22000.795
  • Local chip architecture: AMD64
  • Reproduces in: Remote - Containers (Have not tried it in codespaces)
  • Name of Dev Container Definition with Issue: zyphox-mrp

Steps to Reproduce: I have not found a way to easily reproduce this as it randomly happens to me, but happens almost every time I use VS code. I believe it has to do with branching and pushing. Seems to happen after pushing my changes.

Here is my devcontainer file:

{
  "name": "test",
  "dockerComposeFile": "docker-compose.yaml",
  "service": "app",
  "workspaceFolder": "/workspace",
  "initializeCommand": ".devcontainer/generate-workspace-env.sh --container-workspace-folder '${containerWorkspaceFolder}' --local-workspace-folder '${localWorkspaceFolder}'",
  "postCreateCommand": "bash ./.devcontainer/postCreateCommand.sh",
  "settings": {
    "editor.formatOnSave": true,
    "editor.codeActionsOnSave": {
      "source.fixAll.stylelint": true,
      "source.fixAll.eslint": true
    },
    "files.autoSaveDelay": 500,
    "eslint.validate": [
      "javascript"
    ],
    "git.enableSmartCommit": true,
    "git.confirmSync": false,
    "editor.tabSize": 2,
    "editor.detectIndentation": false,
    "files.eol": "\n",
    "codemetrics.basics.CodeLensHiddenUnder": 10,
    "terminal.integrated.defaultProfile.windows": "Command Prompt",
    "diffEditor.ignoreTrimWhitespace": false,
    "explorer.autoReveal": false,
    "explorer.fileNesting.enabled": true,
    "explorer.fileNesting.patterns": {
      "*.ts": "${capture}.js",
      "*.js": "${capture}.js.map, ${capture}.min.js, ${capture}.d.ts",
      "*.jsx": "${capture}.js",
      "*.tsx": "${capture}.ts",
      "tsconfig.json": "tsconfig.*.json",
      "package.json": "package-lock.json, yarn.lock, Dockerfile*, .*, *.json, webpack*"
    },
    "auto-run-command.rules": [
      {
        "condition": "always",
        "command": "workbench.action.terminal.new"
      }
    ],
    "window.newWindowDimensions": "inherit",
    "debug.toolBarLocation": "docked"
  },
  "extensions": [
    "dbaeumer.vscode-eslint",
    "gabrielgrinberg.auto-run-command",
    "stylelint.vscode-stylelint",
    "kisstkondoros.vscode-codemetrics",
    "mongodb.mongodb-vscode"
  ],
  "forwardPorts": [
    80,
    27017
  ]
}

joezappie avatar Jul 25 '22 18:07 joezappie

are you only seeing the behavior in the 'git' pane of VS Code, or also if you were to do something like git status in the integrated terminal?

Have you tried running a more minimal setup to see if it is something relevant to this config. I would suggest trying without any VS Code settings or extensions running.

If you do find that it is an issue with an extension, vscode has a handy bisect feature to help isolate the problem

joshspicer avatar Jul 29 '22 18:07 joshspicer

This was both in the sidebar pane and if I ran any git commands through the terminal. In the video I linked to, I show that running "git stash" shows "no local changes" as well so git in the container could not detect any changes.

It did seem like the files were being edited however on a branch I was not on. Sometimes, I could switch to other branches and my files would magically appear there. New files however always seemed to show up on the current correct branch. Nothing seemed consistent though so I was hard to figure out exactly what was happening, but I did have it happen 10 or so times.

I did fully delete all my containers/images and volumes to rebuild my project from scratch. I haven't spent much time in that project since but that may have fixed my issue.

Thanks for the info on bisect feature. If the issue persists I'll try that out.

joezappie avatar Jul 29 '22 19:07 joezappie

@joshspicer I just started working in this project again, and unfortunately the issue is back again after committing my changes. After doing so its no longer tracking new changes but new files are tracked.

Its so weird though because I created a new file to see if it was tracked. I then discarded the change in git and all my other changes showed back up after...

To isolate the issue further I've disabled all extensions (except remote containers) and reset all my VS code settings for both the User space and Remote Space and it still occurs.

I supposed it could be an issue with git but I've only seen this happen inside a devcontainer which is why I assumed it was an issue with the remote extension. Seems like the former may be more likely, or an issue with WSL and git and not VS code. Curious if you have any other diagnostics you'd recommend I run in VS code and if not I'll close this.

joezappie avatar Aug 04 '22 03:08 joezappie

I finally stumbled upon the answer to this - git's core.fsmonitor being true.

Searching through the WSL github, turns out someone recently made an issue for it: https://github.com/microsoft/WSL/issues/8622

When reinstalling my computer from scratch, I turned on some of gits experimental features. One of those being the new file system monitor:

image

joezappie avatar Aug 07 '22 23:08 joezappie

I need to reopen this issue. I have not had this issue for months, and all the sudden it is now doing this again. Any change that I have recently committed does NOT get tracked. If I add a new file, that shows up.

I have reinstalled git to verify the experimental file system monitor is disabled, which seemingly before was the issue.

joezappie avatar Jun 29 '23 05:06 joezappie

I'd love some help on this. This continues to be an issue in one of my containers and cannot track down why.

@joshspicer I've notice that if I break my devcontainer so it opens in a recovery container, I can see my changes.

After changing a file - no changes logged by git. image

After editing devcontainer.json to have an error so it opens in recovery, I can see my changed files: image

VSCode and GIT are both latest versions

joezappie avatar Sep 11 '23 17:09 joezappie