我想在同一台计算机上使用两个单独的 GitHub 帐户,因此我为它们设置了 ssh 密钥。两者都工作正常。我不想每次创建新的存储库时都配置我的电子邮件和名称,所以我环顾四周并找到了 git 的“includeIf”部分。
我使用的是 git 版本 2.37.3
这些是我现在的配置文件。
〜/.gitconfig
[user]
email = "home@example.com"
name = "Home"
[includeIf "hasconfig:remote.*.url:git@github.com-Work:*/**"]
email = "work@example.com"
name = "Work"
Run Code Online (Sandbox Code Playgroud)
〜/ .ssh /配置
Host github.com-Home
HostName github.com
User git
IdentityFile ~/.ssh/Home
Host github.com-Work
HostName github.com
User git
IdentityFile ~/.ssh/Work
Run Code Online (Sandbox Code Playgroud)
当我克隆一个存储库git clone git@github.com-Home:Home/repo.git并git config user.name在存储库中运行时,我得到了预期的输出Home
但是,当我为我的工作帐户克隆一个存储库git clone git@github.com-Work:Work/repo.git并git config user.name在存储库中运行时,我得到的Home不是Work. 运行git config remote.origin.url回报git@github.com-Work:Work/repo.git
知道为什么这不起作用吗?
接下来 13 告诉我从客户端组件收集输入并从服务器组件获取数据。如果我想根据客户端的输入获取数据,如何将状态从客户端组件传递到服务器组件。
这个问题看似微不足道,但我找不到答案。假设这letter是一个单个字符串,我如何将字母转换为字符?
let mut letter = String::new();
io::stdin()
.read_line(&mut letter)
.expect("Failed to read line");
Run Code Online (Sandbox Code Playgroud)