Selaa lähdekoodia

2025-04-15 14:25:25

john.hong 3 kuukautta sitten
vanhempi
sitoutus
739fdd968b
2 muutettua tiedostoa jossa 123 lisäystä ja 7 poistoa
  1. 17 7
      .obsidian/workspace.json
  2. 106 0
      工具/git/未命名.md

+ 17 - 7
.obsidian/workspace.json

@@ -13,12 +13,12 @@
             "state": {
               "type": "markdown",
               "state": {
-                "file": "工具/plantuml/基础资料/说明.md",
+                "file": "工具/git/未命名.md",
                 "mode": "source",
                 "source": true
               },
               "icon": "lucide-file",
-              "title": "说明"
+              "title": "未命名"
             }
           }
         ]
@@ -159,6 +159,16 @@
           {
             "id": "94eea621e31ecb63",
             "type": "leaf",
+            "state": {
+              "type": "reminder-list",
+              "state": {},
+              "icon": "lucide-file",
+              "title": "Plugin no longer active"
+            }
+          },
+          {
+            "id": "ef0b04f332fbe701",
+            "type": "leaf",
             "state": {
               "type": "reminder-list",
               "state": {},
@@ -176,9 +186,9 @@
   },
   "left-ribbon": {
     "hiddenItems": {
-      "canvas:新建白板": false,
       "switcher:打开快速切换": false,
       "graph:查看关系图谱": false,
+      "canvas:新建白板": false,
       "daily-notes:打开/创建今天的日记": false,
       "templates:插入模板": false,
       "command-palette:打开命令面板": false
@@ -186,7 +196,11 @@
   },
   "active": "159db3b59d8f09cd",
   "lastOpenFiles": [
+    "工具/git/一个开发人员需要知道的 commit 规范.md",
+    "工具/git/未命名.md",
+    "工具/git/Git 设置本地分支对应的远程分支的两类方法.md",
     "Spring/102/任务总览.md",
+    "工具/plantuml/基础资料/说明.md",
     "每日工作笔记/2024/2024-04-23.md",
     "每日工作笔记/2023/2023-09-07.md",
     "每日工作笔记/2025-01-02.md",
@@ -209,7 +223,6 @@
     "每日工作笔记/2024-07-15.md",
     "每日工作笔记/2024/2024-07-01.md",
     "工具/plantuml/生成的内容/Consume4.svg",
-    "工具/plantuml/基础资料/说明.md",
     "工具/plantuml/生成的内容/Consume2.svg",
     "工具/plantuml/生成的内容/Consume2.png",
     "工具/plantuml/生成的内容/MemberLevel.wsl",
@@ -229,9 +242,6 @@
     "工具/plantuml/未命名文件夹",
     "思维导图/MemberLevel2.svg",
     "思维导图/MemberLevel.svg",
-    "每日工作笔记/2023/2023-10-24.md",
-    "每日工作笔记/2025-03-18.md",
-    "项目说明.md",
     "未命名.canvas",
     "未命名 1.canvas",
     "未命名 2.canvas",

+ 106 - 0
工具/git/未命名.md

@@ -0,0 +1,106 @@
+是的,在提交到 GitHub 时可以通过配置 Git 客户端来指定特定的 SSH 密钥(SSH Key)。以下是具体方法:
+
+---
+
+### **方法 1:通过 `~/.ssh/config` 文件指定密钥**
+1. **编辑 SSH 配置文件**  
+   打开或创建 `~/.ssh/config` 文件(Linux/macOS 路径,Windows 在 `C:\Users\你的用户名\.ssh\config`):
+   ```bash
+   nano ~/.ssh/config
+   ```
+
+2. **添加规则**  
+   为 GitHub 的域名指定密钥文件路径,例如:
+   ```ssh-config
+   Host github.com
+     HostName github.com
+     User git
+     IdentityFile ~/.ssh/你的私钥文件名  # 例如 ~/.ssh/id_ed25519_work
+     IdentitiesOnly yes  # 强制只使用指定的密钥
+   ```
+
+3. **测试连接**  
+   ```bash
+   ssh -T git@github.com
+   ```
+   看到 `You've successfully authenticated` 表示配置成功。
+
+---
+
+### **方法 2:临时通过 `GIT_SSH_COMMAND` 指定密钥**
+在提交时通过环境变量临时指定密钥:
+```bash
+GIT_SSH_COMMAND="ssh -i ~/.ssh/你的私钥文件名" git push origin main
+```
+
+---
+
+### **方法 3:使用 `core.sshCommand` 配置(项目级或全局)**
+1. **项目级配置**(仅对当前仓库生效):
+   ```bash
+   git config core.sshCommand "ssh -i ~/.ssh/你的私钥文件名"
+   ```
+
+2. **全局配置**(所有仓库生效):
+   ```bash
+   git config --global core.sshCommand "ssh -i ~/.ssh/你的私钥文件名"
+   ```
+
+---
+
+### **注意事项**
+1. **密钥权限**  
+   确保私钥文件权限为 `600`:
+   ```bash
+   chmod 600 ~/.ssh/你的私钥文件名
+   ```
+
+2. **公钥配对**  
+   将对应的公钥(`.pub` 文件内容)添加到 GitHub 账户的 **Settings → SSH and GPG keys** 中。
+
+3. **多账号场景**  
+   如果同时使用多个 GitHub 账号,需在 `~/.ssh/config` 中为每个账号配置不同的 Host 别名(如 `github-work` 和 `github-personal`),并修改仓库的远程 URL 为对应的别名:
+   ```bash
+   git remote set-url origin git@github-work:用户名/仓库名.git
+   ```
+
+---
+
+### **验证是否生效**
+提交时,Git 会输出使用的密钥路径(需开启 SSH 调试):
+```bash
+GIT_SSH_COMMAND="ssh -v" git push origin main 2>&1 | grep "Offering public key"
+```
+
+通过以上方法,你可以灵活地为不同仓库或场景指定特定的 SSH 密钥。
+
+
+
+普通github项目
+```
+git config core.sshCommand "ssh -i ~/.ssh/github"
+# 临时使用
+GIT_SSH_COMMAND="ssh -i ~/.ssh/github"
+```
+
+普通github_va项目
+```
+git config core.sshCommand "ssh -i ~/.ssh/id_ed25519"
+# 临时使用
+GIT_SSH_COMMAND="ssh -i ~/.ssh/id_ed25519"
+```
+
+普通gitee项目
+```
+git config core.sshCommand "ssh -i ~/.ssh/gitee"
+# 临时使用
+GIT_SSH_COMMAND="ssh -i ~/.ssh/gitee"
+```
+
+普通kerry_github项目
+```
+git config core.sshCommand "ssh -i ~/.ssh/kerry"
+
+# 临时使用
+GIT_SSH_COMMAND="ssh -i ~/.ssh/kerry"
+```