-
Notifications
You must be signed in to change notification settings - Fork 19
add to ch3 sec1 subsec2 1 #109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Plucky923
merged 1 commit into
hust-open-atom-club:main
from
xzss-ops:add-to-ch3-sec1-subsec2-1
Aug 24, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,18 @@ | |
|
||
在使用 Git 之前,首先需要进行一些基本的配置,包括设置用户名和邮箱。这些信息会与每次提交(Commit)关联,用于标识代码的贡献者。 | ||
|
||
### 打开终端(Terminal) | ||
|
||
如果你使用的是 Windows: | ||
|
||
- 推荐安装 [Git for Windows](https://git-scm.com/download/win),安装后你会获得一个名为 **Git Bash** 的终端工具,点击即可使用。 | ||
|
||
如果你使用的是 macOS 或 Linux: | ||
|
||
- 打开自带的 **Terminal** 应用程序即可。 | ||
|
||
安装完成后,就可以输入下面步骤的命令进行 Git 的基础配置 | ||
|
||
### 配置用户名和邮箱 | ||
|
||
- **命令**: | ||
|
@@ -17,13 +29,23 @@ | |
git config --global user.email "你的邮箱" | ||
``` | ||
|
||
```bash | ||
# 正确示例 | ||
git config --global user.name "John Doe" | ||
git config --global user.email "[email protected]" | ||
# 错误示例(缺少引号会导致问题) | ||
git config --global user.name John Doe # 错误!用户名中有空格必须加引号 | ||
``` | ||
|
||
- **作用**: | ||
- `user.name`:设置提交代码时显示的作者名称。 | ||
- `user.email`:设置提交代码时显示的作者邮箱。 | ||
- `--global`:表示全局配置,适用于当前用户的所有仓库。如果只想为某个仓库单独配置,可以去掉 `--global` 参数。 | ||
|
||
- **提示** | ||
- 有些时候,你不想让自己的邮箱与这个 git 用户有关联,可以使用 GitHub 等平台提供的隐私邮箱 | ||
|
||
- 如果你不希望暴露自己的真实邮箱,可以使用 GitHub 提供的隐私邮箱(形如 `用户名@users.noreply.github.com`) | ||
- 查看方法:登录 GitHub,进入 **Settings -> Emails**,可以找到你的隐私邮箱地址。 | ||
|
||
### 查看配置信息 | ||
|
||
- **命令**: | ||
|
@@ -52,6 +74,19 @@ SSH(Secure Shell)是一种加密的网络协议,用于安全地访问远 | |
|
||
### 生成 SSH 密钥 | ||
|
||
#### 什么是 SSH 密钥? | ||
|
||
SSH 密钥是一个由“私钥 + 公钥”组成的安全认证方式,类似于“锁和钥匙”。你将公钥添加到 GitHub 账户后,GitHub 就知道“这个钥匙是你自己的”,从而允许你访问代码仓库,无需每次都输入用户名密码。 | ||
|
||
```mermaid | ||
graph LR | ||
A[你的电脑] -->|生成密钥对| B[私钥 id_ed25519] | ||
A -->|生成密钥对| C[公钥 id_ed25519.pub] | ||
C -->|添加到| D[GitHub 账户] | ||
A -->|使用私钥认证| E[GitHub 服务器] | ||
E -->|验证公钥匹配| D | ||
``` | ||
|
||
1. **检查是否已有 SSH 密钥**: | ||
|
||
打开终端,输入以下命令: | ||
|
@@ -60,7 +95,9 @@ SSH(Secure Shell)是一种加密的网络协议,用于安全地访问远 | |
ls ~/.ssh/ | ||
``` | ||
|
||
如果文件存在,说明已有 SSH 密钥,可以跳过生成步骤。 | ||
如果看到 id_ed25519 和 id_ed25519.pub 文件,说明已有密钥 | ||
|
||
在文件管理器中查看路径:C:/Users/你的用户名/.ssh/ (Windows) 或 /home/你的用户名/.ssh/ (macOS/Linux) | ||
|
||
2. **生成新的 SSH 密钥**: | ||
|
||
|
@@ -99,9 +136,15 @@ SSH(Secure Shell)是一种加密的网络协议,用于安全地访问远 | |
|
||
2. **添加到 GitHub**: | ||
|
||
登录 GitHub,进入 **Settings** -> **SSH and GPG keys**。 | ||
1.登录 GitHub,进入 **Settings** -> **SSH and GPG keys** | ||
|
||
2.点击 **New SSH key** | ||
|
||
3.在 Title 中输入设备名称(如 "My Laptop") | ||
|
||
点击 **New SSH key**,将复制的公钥粘贴到 Key 字段中,设置标题并保存。 | ||
4.在 Key 字段粘贴公钥内容 | ||
|
||
5.点击 **Add SSH key** | ||
|
||
### 测试 SSH 连接 | ||
|
||
|
@@ -113,6 +156,33 @@ SSH(Secure Shell)是一种加密的网络协议,用于安全地访问远 | |
|
||
- 如果显示 `Hi 用户名! You've successfully authenticated ...`,说明 SSH 配置成功。 | ||
|
||
```mermaid | ||
flowchart TD | ||
A[执行 ssh -T [email protected]] --> B{连接成功?} | ||
B -->|是| C[显示欢迎消息] | ||
B -->|否| D[检查密钥是否添加] | ||
D --> E[检查ssh-agent是否运行] | ||
E --> F[尝试不同端口] | ||
F --> G[检查网络/代理设置] | ||
G --> H[查看详细日志 ssh -vT] | ||
``` | ||
|
||
#### 如果测试失败怎么办? | ||
|
||
- 确保你生成了 SSH 密钥并添加到了 GitHub。 | ||
- 检查是否执行了 `ssh-add ~/.ssh/id_ed25519`。 | ||
- 有时 Git Bash 或 WSL 可能未自动启动 ssh-agent,可以先执行: | ||
|
||
```bash | ||
eval "$(ssh-agent -s)" | ||
``` | ||
|
||
- 如果还是失败,可以在终端中运行以下命令查看调试信息: | ||
|
||
```bash | ||
ssh -vT [email protected] | ||
``` | ||
|
||
### 使用 SSH 克隆仓库 | ||
|
||
- 使用 SSH 地址克隆远程仓库: | ||
|
@@ -121,6 +191,16 @@ SSH(Secure Shell)是一种加密的网络协议,用于安全地访问远 | |
git clone [email protected]:用户名/仓库名.git | ||
``` | ||
|
||
- **两种克隆方式对比**: | ||
|
||
```bash | ||
# HTTPS 方式(需要每次输入密码) | ||
git clone https://github.com/用户名/仓库名.git | ||
|
||
# SSH 方式(配置密钥后无需密码) | ||
git clone [email protected]:用户名/仓库名.git | ||
``` | ||
|
||
### 将现有仓库切换为 SSH 连接 | ||
|
||
- 如果已经使用 HTTPS 克隆了仓库,可以通过以下命令切换为 SSH: | ||
|
@@ -131,16 +211,26 @@ SSH(Secure Shell)是一种加密的网络协议,用于安全地访问远 | |
|
||
- 使用 `git remote -v` 查看远程仓库地址,确认是否切换成功。 | ||
|
||
- 如果你的网络环境比较特殊,可以修改 ssh 配置 (~/.ssh/config) | ||
- 如果你的网络环境比较特殊(如不能访问 GitHub,或 22 端口被屏蔽),你可以配置 SSH 客户端。 | ||
|
||
- 首先,打开(或创建)`~/.ssh/config` 文件: | ||
|
||
```bash | ||
nano ~/.ssh/config | ||
``` | ||
|
||
- 然后粘贴如下配置(按实际情况调整代理或端口): | ||
|
||
```bash | ||
Host github.com | ||
Hostname ssh.github.com | ||
Port 443 #如果你的网络环境不允许使用 22 端口进行连接 | ||
User git | ||
ProxyCommand nc -v -x 127.0.0.1:10808 %h %p #如果需要使用代理才能访问互联网 | ||
Hostname ssh.github.com | ||
Port 443 | ||
User git | ||
ProxyCommand nc -v -x 127.0.0.1:10808 %h %p # 如果你使用代理访问 GitHub | ||
``` | ||
|
||
- 保存后再次测试 SSH 连接。 | ||
|
||
--- | ||
|
||
## 3。Git 最为基础的命令 | ||
|
@@ -204,9 +294,67 @@ SSH(Secure Shell)是一种加密的网络协议,用于安全地访问远 | |
|
||
--- | ||
|
||
## Git 工作流程概览图 | ||
|
||
```mermaid | ||
flowchart TD | ||
A[配置用户信息] --> B[生成SSH密钥] | ||
B --> C[添加密钥到GitHub] | ||
C --> D[克隆仓库] | ||
D --> E[修改文件] | ||
E --> F[查看状态] | ||
|
||
subgraph 本地操作 | ||
E | ||
F | ||
end | ||
|
||
subgraph 远程连接 | ||
C | ||
D | ||
end | ||
``` | ||
|
||
--- | ||
|
||
## 总结 | ||
|
||
1. 如何配置 Git 的用户名和邮箱,以便正确标识代码贡献者。 | ||
2. 如何使用 `git init` 初始化一个新的 Git 仓库。 | ||
3. 如何使用 `git clone` 克隆远程仓库到本地。 | ||
4. 如何使用 `git status` 查看仓库的当前状态。 | ||
|
||
## 🧪 实践任务 | ||
|
||
1. 配置用户名和邮箱 | ||
|
||
```bash | ||
git config --global user.name "你的名字" | ||
git config --global user.email "你的邮箱" | ||
git config --list | grep user # 检查配置是否正确 | ||
``` | ||
|
||
2. 创建并添加 SSH 密钥 | ||
|
||
```bash | ||
ssh-keygen -t ed25519 -C "你的邮箱" # 按三次回车 | ||
cat ~/.ssh/id_ed25519.pub # 复制输出的所有内容 | ||
# 添加到 GitHub 后测试: | ||
ssh -T [email protected] | ||
``` | ||
|
||
3. 在 GitHub 上找到一个开源仓库(如 [https://github.com/octocat/Hello-World](https://github.com/octocat/Hello-World)),用 SSH 方式克隆它到本地: | ||
|
||
```bash | ||
git clone [email protected]:octocat/Hello-World.git | ||
``` | ||
|
||
4. 进入该项目文件夹,执行以下命令: | ||
|
||
```bash | ||
cd Hello-World | ||
git status | ||
# 应该看到:"nothing to commit, working tree clean" | ||
``` | ||
|
||
如果你成功完成以上步骤,恭喜你!已经具备基本的 Git 配置与使用能力。 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这部分是不是应该先安装git