Git "Author identity unknown" in VSCode Devcontainer



在vscode devcontainer中执行git操作(如git commit),报错如下:

Author identity unknown
*** Please tell me who you are.
Run
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.

是否有一种方法可以在启动devcontainer时从主机继承git配置?

在我的例子中,我在devcontainer.jsonpostCreateCommand中有一个git config --global ...命令:

{
// ...
"postCreateCommand": "git config --global --add safe.directory ${containerWorkspaceFolder}",
}

删除后,主机系统的.gitconfig设置再次正确传输到DevContainer。根据这个答案,也应该可以使用postAttachCommand属性来代替。

在我看来,容器启动和postCreateCommand似乎在互相争斗,因为它们都使用git config --global ...命令。