简短描述:
在 devcontainer 内,git UI 不会更新,即使
git.autorefresh: true
已设置。在开发容器之外它可以正常工作。也许与这个堆栈溢出问题相关git not update
我的系统:
工作流程:
在 Windows 中,我克隆(git bash 终端)一个存储库。我在 VS Code 中打开这个存储库。我添加我的
devcontainer.json
文件和我的 docker-compose.yml
。我在 VS Code (cmd) 中使用终端并使用
git add .
--> 之后我在 git add 中看到这两个文件已从更改移动到暂存更改。
git commit -m "add devcontainer files"
--> 之后我在 git 扩展中看到没有更多更改,我现在可以同步或发布。
现在我在 VS Code 中使用命令 Dev Containers: Reopen in Container
。
现在我使用 first.py
在此处添加一个新文件 touch first.py
。
这显示在 git 扩展 UI 下的 Changes
下。
我使用终端(bash)并写 git add .
现在文件不会转到 Staged Changes
,而是保留在 Changes
。即使我运行git commit -m "add first.py"
也会发生这种情况。 git 扩展没有显示任何更改。仅当我明确单击小刷新符号时,它才会更新。
devcontainer.json:
{
"name": "Test",
"dockerComposeFile": [
"../docker-compose.yml",
"docker-compose.yml"
],
"service": "testservice",
"workspaceFolder": "/var/www/html"
}
预期行为:
就像在本地一样,我希望 devcontainer 内的 git 插件能够通过终端识别我的更改。
已尝试解决方案步骤(随后重建容器):
git.autorefresh: true
设置 git add .
,日志中显示如下:
2023-08-08 09:17:29.169 [debug] [.git] Change: c:\projects\test_git_problems\.git\index
2023-08-08 09:17:30.172 [trace] Operation start: Status (blocking: false, readOnly: false; retry: false; showProgress: true)
2023-08-08 09:17:30.244 [info] > git config --get commit.template [69ms]
2023-08-08 09:17:30.248 [info] > git for-each-ref --format=%(refname)%00%(upstream:short)%00%(objectname)%00%(upstream:track)%00%(upstream:remotename)%00%(upstream:remoteref) --ignore-case refs/heads/master refs/remotes/master [71ms]
2023-08-08 09:17:30.289 [trace] Operation start: GetObjectDetails (blocking: false, readOnly: true; retry: false; showProgress: false)
2023-08-08 09:17:30.321 [info] > git status -z -uall [70ms]
在 devcontainer 内部,具有日志记录级别跟踪的 git 输出中没有发生任何事情。
后来我看了下
Help --> Toggle Developer Tools
。我在控制台下过滤了“文件观察器”。在 devcontainer 中我看到以下内容:
T
RACE [File Watcher (node.js)] [raw] ["change"] globalStorage
log.ts:401 TRACE [File Watcher (node.js)] [CHANGED] c:\Users\<User>\AppData\Roaming\Code\User\globalStorage
log.ts:401 TRACE [File Watcher (node.js)] >> normalized [CHANGED] c:\Users\<User>\AppData\Roaming\Code\User\globalStorage
在本地我看到以下内容:
TRACE [File Watcher (node.js)] [CHANGED] c:\projects\test_git_problems\.git\index
log.ts:401 TRACE [File Watcher (node.js)] >> ignored (not included) c:\projects\test_git_problems\.git\index
log.ts:401 TRACE [File Watcher (parcel)] >> normalized [DELETED] c:\projects\test_git_problems\.git\index.lock
log.ts:401 TRACE [File Watcher (parcel)] >> normalized [CHANGED] c:\projects\test_git_problems\.git\index
这给了我以下想法:
chmod -R 777 .git
已执行不幸的是也没有成功。
我的测试存储库也只包含 5 个文件,因此文件观察者的最大数量应该不是问题。使用
cat /proc/sys/fs/inotify/max_user_watches
我得到:524288
其他测试/发现:
当我在 devcontainer 中创建一个文件夹并运行
git init
时,git 插件将按预期工作。因此我怀疑这可能是 Windows 造成的。
从官方文档页面上找到的信息以及vscode问题跟踪器中的这些两个评论中,我验证了这个问题(我在我的Windows机器上也遇到过)确实消失了,如果我:
code .
打开 vscode。如果我随后在 devcontainer 中重新打开,所有版本控制 UI 都会按预期更新(并且一切都感觉比以前更快)。