“与容器共享 Git 凭据”不起作用

t29*_*ato 6 git visual-studio-code

我做了什么

  1. 全局设置 git 配置。
(local) $ git config --global user.email "you@example.com"
(local) $ git config --global user.name "Your Name"
Run Code Online (Sandbox Code Playgroud)
  1. Remote-Container:重建容器

  2. git 提交

(Remote-Container) $ git commit -m hogehoge
Run Code Online (Sandbox Code Playgroud)

结果

*** 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.

fatal: unable to auto-detect email address (got 'root@aaaaaaaaaaa.(none)')
Run Code Online (Sandbox Code Playgroud)

参考号

https://code.visualstudio.com/docs/remote/containers#_sharing-git-credentials-with-your-container

sau*_*edo 11

我遇到了类似的问题,因为我正在git config --global运行postCreateCommand。我想更改容器中的差异和合并工具。但是,我的用户名和密码从我的.gitconfig. 我还不明白原因,但我通过添加命令来解决这个问题postAttachCommand

因此,在.devcontainer/devcontainer.json, 而不是:

{
  ...
  postCreateCommand": "git config --global diff.tool ...",
  ...
}
Run Code Online (Sandbox Code Playgroud)

我用:

{
  ...
  postAttachCommand": "git config --global diff.tool ...",
  ...
}
Run Code Online (Sandbox Code Playgroud)

我想知道你的情况是否无关。了解您的.devcontainer/devcontainer.json. 尽管如此,我还是希望这些信息对遇到类似问题的其他用户有用。