149 lines
4.2 KiB
Markdown
149 lines
4.2 KiB
Markdown
# Git 使用说明
|
||
|
||
## 1. 为什么需要在 WSL 中使用 Git
|
||
|
||
本项目包含 Linux 符号链接文件(如 `SDK/OpenCV320/Arm/aarch64/` 和 `SDK/OpenCV480/Arm/aarch64/lib/` 目录下的 `.so` 文件),这些符号链接在 Windows 原生环境下无法正确处理。
|
||
|
||
**原因:**
|
||
- Windows 的符号链接与 Linux 的符号链接格式不兼容
|
||
- 在 Windows 下使用 Git 操作这些文件会导致符号链接被破坏或转换为普通文件
|
||
- WSL (Windows Subsystem for Linux) 可以正确处理 Linux 符号链接
|
||
|
||
**建议:**
|
||
- 所有 Git 操作(clone、pull、push、commit 等)都应在 WSL 环境中进行
|
||
- 代码编辑和编译可以在 Windows 下进行,但版本控制操作需要在 WSL 中完成
|
||
|
||
## 2. Ubuntu 下使用 Git 所需安装的软件
|
||
|
||
### 基础安装
|
||
|
||
```bash
|
||
# 更新软件包列表
|
||
sudo apt update
|
||
|
||
# 安装 Git
|
||
sudo apt install git
|
||
|
||
# 验证安装
|
||
git --version
|
||
```
|
||
|
||
### 配置 Git 用户信息
|
||
|
||
```bash
|
||
# 设置用户名
|
||
git config --global user.name "你的用户名"
|
||
|
||
# 设置邮箱
|
||
git config --global user.email "你的邮箱@example.com"
|
||
|
||
# 查看配置
|
||
git config --list
|
||
```
|
||
|
||
### 可选工具安装
|
||
|
||
```bash
|
||
# Git 图形化界面工具
|
||
sudo apt install gitk git-gui
|
||
|
||
# Git 凭证存储(避免重复输入密码)
|
||
sudo apt install git-credential-manager
|
||
|
||
# 或使用缓存方式存储凭证
|
||
git config --global credential.helper cache
|
||
git config --global credential.helper 'cache --timeout=3600'
|
||
```
|
||
|
||
## 3. Git 管理常用命令
|
||
|
||
### 仓库操作
|
||
|
||
| 命令 | 说明 |
|
||
|------|------|
|
||
| `git clone <url>` | 克隆远程仓库 |
|
||
| `git init` | 初始化本地仓库 |
|
||
| `git remote -v` | 查看远程仓库地址 |
|
||
| `git remote add origin <url>` | 添加远程仓库 |
|
||
|
||
### 状态查看
|
||
|
||
| 命令 | 说明 |
|
||
|------|------|
|
||
| `git status` | 查看工作区状态 |
|
||
| `git log` | 查看提交历史 |
|
||
| `git log --oneline` | 查看简洁提交历史 |
|
||
| `git log --graph` | 图形化显示提交历史 |
|
||
| `git diff` | 查看未暂存的修改 |
|
||
| `git diff --staged` | 查看已暂存的修改 |
|
||
|
||
### 文件操作
|
||
|
||
| 命令 | 说明 |
|
||
|------|------|
|
||
| `git add <file>` | 添加文件到暂存区 |
|
||
| `git add .` | 添加所有修改到暂存区 |
|
||
| `git rm <file>` | 删除文件并暂存 |
|
||
| `git mv <old> <new>` | 重命名/移动文件 |
|
||
| `git checkout -- <file>` | 撤销工作区修改 |
|
||
| `git reset HEAD <file>` | 取消暂存 |
|
||
|
||
### 提交操作
|
||
|
||
| 命令 | 说明 |
|
||
|------|------|
|
||
| `git commit -m "提交信息"` | 提交到本地仓库 |
|
||
| `git commit -am "提交信息"` | 添加并提交(仅已跟踪文件) |
|
||
| `git commit --amend` | 修改最后一次提交 |
|
||
|
||
### 分支操作
|
||
|
||
| 命令 | 说明 |
|
||
|------|------|
|
||
| `git branch` | 查看本地分支 |
|
||
| `git branch -a` | 查看所有分支(含远程) |
|
||
| `git branch <name>` | 创建分支 |
|
||
| `git checkout <branch>` | 切换分支 |
|
||
| `git checkout -b <name>` | 创建并切换分支 |
|
||
| `git merge <branch>` | 合并分支到当前分支 |
|
||
| `git branch -d <name>` | 删除分支 |
|
||
|
||
### 远程同步
|
||
|
||
| 命令 | 说明 |
|
||
|------|------|
|
||
| `git fetch` | 获取远程更新(不合并) |
|
||
| `git pull` | 拉取并合并远程更新 |
|
||
| `git push` | 推送到远程仓库 |
|
||
| `git push -u origin <branch>` | 推送并设置上游分支 |
|
||
| `git push origin --delete <branch>` | 删除远程分支 |
|
||
|
||
### 撤销与回退
|
||
|
||
| 命令 | 说明 |
|
||
|------|------|
|
||
| `git reset --soft HEAD~1` | 撤销最后一次提交(保留修改在暂存区) |
|
||
| `git reset --mixed HEAD~1` | 撤销最后一次提交(保留修改在工作区) |
|
||
| `git reset --hard HEAD~1` | 撤销最后一次提交(丢弃所有修改) |
|
||
| `git revert <commit>` | 创建新提交来撤销指定提交 |
|
||
|
||
### 暂存工作区
|
||
|
||
| 命令 | 说明 |
|
||
|------|------|
|
||
| `git stash` | 暂存当前工作区 |
|
||
| `git stash list` | 查看暂存列表 |
|
||
| `git stash pop` | 恢复并删除暂存 |
|
||
| `git stash apply` | 恢复暂存(不删除) |
|
||
| `git stash drop` | 删除暂存 |
|
||
|
||
### 标签操作
|
||
|
||
| 命令 | 说明 |
|
||
|------|------|
|
||
| `git tag` | 查看标签列表 |
|
||
| `git tag <name>` | 创建轻量标签 |
|
||
| `git tag -a <name> -m "说明"` | 创建附注标签 |
|
||
| `git push origin <tag>` | 推送标签到远程 |
|
||
| `git push origin --tags` | 推送所有标签 |
|