Compare commits
4 Commits
78e81da80f
...
435a7caa66
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
435a7caa66 | ||
| 0f00dfbb5d | |||
|
|
4c1a38fd1f | ||
|
|
ba2832abf8 |
244
GIT_GUIDE.md
244
GIT_GUIDE.md
@@ -1,244 +0,0 @@
|
|||||||
# Git 操作指南
|
|
||||||
|
|
||||||
## 快速上传脚本
|
|
||||||
|
|
||||||
双击运行 `git_upload.bat` 即可快速上传代码到 Git 仓库。
|
|
||||||
|
|
||||||
## 常用 Git 命令
|
|
||||||
|
|
||||||
### 1. 基础操作
|
|
||||||
|
|
||||||
```powershell
|
|
||||||
# 查看当前状态
|
|
||||||
& "C:\Program Files\Git\bin\git.exe" status
|
|
||||||
|
|
||||||
# 查看修改内容
|
|
||||||
& "C:\Program Files\Git\bin\git.exe" diff
|
|
||||||
|
|
||||||
# 查看提交历史
|
|
||||||
& "C:\Program Files\Git\bin\git.exe" log --oneline
|
|
||||||
|
|
||||||
# 查看最近 5 次提交
|
|
||||||
& "C:\Program Files\Git\bin\git.exe" log -5
|
|
||||||
```
|
|
||||||
|
|
||||||
### 2. 提交代码
|
|
||||||
|
|
||||||
```powershell
|
|
||||||
# 添加所有文件
|
|
||||||
& "C:\Program Files\Git\bin\git.exe" add -A
|
|
||||||
|
|
||||||
# 添加指定文件
|
|
||||||
& "C:\Program Files\Git\bin\git.exe" add 文件名
|
|
||||||
|
|
||||||
# 提交更改
|
|
||||||
& "C:\Program Files\Git\bin\git.exe" commit -m "提交信息"
|
|
||||||
|
|
||||||
# 添加并提交(一步完成)
|
|
||||||
& "C:\Program Files\Git\bin\git.exe" commit -am "提交信息"
|
|
||||||
```
|
|
||||||
|
|
||||||
### 3. 推送到远程仓库
|
|
||||||
|
|
||||||
```powershell
|
|
||||||
# 推送到远程仓库
|
|
||||||
& "C:\Program Files\Git\bin\git.exe" push
|
|
||||||
|
|
||||||
# 首次推送(设置上游分支)
|
|
||||||
& "C:\Program Files\Git\bin\git.exe" push -u origin main
|
|
||||||
|
|
||||||
# 强制推送(谨慎使用)
|
|
||||||
& "C:\Program Files\Git\bin\git.exe" push --force
|
|
||||||
```
|
|
||||||
|
|
||||||
### 4. 拉取代码
|
|
||||||
|
|
||||||
```powershell
|
|
||||||
# 拉取远程代码
|
|
||||||
& "C:\Program Files\Git\bin\git.exe" pull
|
|
||||||
|
|
||||||
# 拉取并合并
|
|
||||||
& "C:\Program Files\Git\bin\git.exe" pull origin main
|
|
||||||
```
|
|
||||||
|
|
||||||
### 5. 分支操作
|
|
||||||
|
|
||||||
```powershell
|
|
||||||
# 查看所有分支
|
|
||||||
& "C:\Program Files\Git\bin\git.exe" branch -a
|
|
||||||
|
|
||||||
# 创建新分支
|
|
||||||
& "C:\Program Files\Git\bin\git.exe" branch 分支名
|
|
||||||
|
|
||||||
# 切换分支
|
|
||||||
& "C:\Program Files\Git\bin\git.exe" checkout 分支名
|
|
||||||
|
|
||||||
# 创建并切换到新分支
|
|
||||||
& "C:\Program Files\Git\bin\git.exe" checkout -b 分支名
|
|
||||||
|
|
||||||
# 删除本地分支
|
|
||||||
& "C:\Program Files\Git\bin\git.exe" branch -d 分支名
|
|
||||||
|
|
||||||
# 删除远程分支
|
|
||||||
& "C:\Program Files\Git\bin\git.exe" push origin --delete 分支名
|
|
||||||
```
|
|
||||||
|
|
||||||
### 6. 撤销操作
|
|
||||||
|
|
||||||
```powershell
|
|
||||||
# 撤销工作区的修改
|
|
||||||
& "C:\Program Files\Git\bin\git.exe" restore 文件名
|
|
||||||
|
|
||||||
# 撤销所有工作区的修改
|
|
||||||
& "C:\Program Files\Git\bin\git.exe" restore .
|
|
||||||
|
|
||||||
# 撤销暂存区的修改
|
|
||||||
& "C:\Program Files\Git\bin\git.exe" reset HEAD 文件名
|
|
||||||
|
|
||||||
# 撤销最后一次提交(保留修改)
|
|
||||||
& "C:\Program Files\Git\bin\git.exe" reset --soft HEAD~1
|
|
||||||
|
|
||||||
# 撤销最后一次提交(丢弃修改)
|
|
||||||
& "C:\Program Files\Git\bin\git.exe" reset --hard HEAD~1
|
|
||||||
```
|
|
||||||
|
|
||||||
### 7. 远程仓库操作
|
|
||||||
|
|
||||||
```powershell
|
|
||||||
# 查看远程仓库
|
|
||||||
& "C:\Program Files\Git\bin\git.exe" remote -v
|
|
||||||
|
|
||||||
# 添加远程仓库
|
|
||||||
& "C:\Program Files\Git\bin\git.exe" remote add origin 远程仓库地址
|
|
||||||
|
|
||||||
# 删除远程仓库
|
|
||||||
& "C:\Program Files\Git\bin\git.exe" remote remove origin
|
|
||||||
|
|
||||||
# 修改远程仓库地址
|
|
||||||
& "C:\Program Files\Git\bin\git.exe" remote set-url origin 新地址
|
|
||||||
```
|
|
||||||
|
|
||||||
### 8. 查看文件
|
|
||||||
|
|
||||||
```powershell
|
|
||||||
# 查看已跟踪的文件
|
|
||||||
& "C:\Program Files\Git\bin\git.exe" ls-files
|
|
||||||
|
|
||||||
# 查看被忽略的文件
|
|
||||||
& "C:\Program Files\Git\bin\git.exe" status --ignored
|
|
||||||
|
|
||||||
# 查看文件大小
|
|
||||||
& "C:\Program Files\Git\bin\git.exe" ls-files -s
|
|
||||||
```
|
|
||||||
|
|
||||||
## 完整上传流程
|
|
||||||
|
|
||||||
### 方式一:使用脚本(推荐)
|
|
||||||
|
|
||||||
```powershell
|
|
||||||
# 双击运行 git_upload.bat
|
|
||||||
# 按照提示输入提交信息即可
|
|
||||||
```
|
|
||||||
|
|
||||||
### 方式二:手动执行命令
|
|
||||||
|
|
||||||
```powershell
|
|
||||||
# 1. 查看当前状态
|
|
||||||
& "C:\Program Files\Git\bin\git.exe" status
|
|
||||||
|
|
||||||
# 2. 添加所有修改的文件
|
|
||||||
& "C:\Program Files\Git\bin\git.exe" add -A
|
|
||||||
|
|
||||||
# 3. 提交更改
|
|
||||||
& "C:\Program Files\Git\bin\git.exe" commit -m "你的提交信息"
|
|
||||||
|
|
||||||
# 4. 推送到远程仓库
|
|
||||||
& "C:\Program Files\Git\bin\git.exe" push
|
|
||||||
```
|
|
||||||
|
|
||||||
## 项目配置信息
|
|
||||||
|
|
||||||
- **远程仓库地址**: `http://lmhrt.cn:6771/ming/Rader_Success_5.git`
|
|
||||||
- **主分支**: `main`
|
|
||||||
- **Git 路径**: `C:\Program Files\Git\bin\git.exe`
|
|
||||||
|
|
||||||
## 常见问题
|
|
||||||
|
|
||||||
### 1. 推送失败,提示需要拉取
|
|
||||||
|
|
||||||
```powershell
|
|
||||||
# 先拉取远程代码
|
|
||||||
& "C:\Program Files\Git\bin\git.exe" pull
|
|
||||||
|
|
||||||
# 解决冲突后再推送
|
|
||||||
& "C:\Program Files\Git\bin\git.exe" push
|
|
||||||
```
|
|
||||||
|
|
||||||
### 2. 忘记添加 .gitignore
|
|
||||||
|
|
||||||
```powershell
|
|
||||||
# 从暂存区移除已添加的文件
|
|
||||||
& "C:\Program Files\Git\bin\git.exe" rm -r --cached .pio
|
|
||||||
|
|
||||||
# 提交更改
|
|
||||||
& "C:\Program Files\Git\bin\git.exe" commit -m "Remove .pio from tracking"
|
|
||||||
& "C:\Program Files\Git\bin\git.exe" push
|
|
||||||
```
|
|
||||||
|
|
||||||
### 3. 修改最后一次提交信息
|
|
||||||
|
|
||||||
```powershell
|
|
||||||
# 修改最后一次提交(未推送)
|
|
||||||
& "C:\Program Files\Git\bin\git.exe" commit --amend -m "新的提交信息"
|
|
||||||
```
|
|
||||||
|
|
||||||
### 4. 查看文件历史
|
|
||||||
|
|
||||||
```powershell
|
|
||||||
# 查看指定文件的历史
|
|
||||||
& "C:\Program Files\Git\bin\git.exe" log --follow 文件名
|
|
||||||
|
|
||||||
# 查看指定文件在某次提交的内容
|
|
||||||
& "C:\Program Files\Git\bin\git.exe" show 提交哈希:文件名
|
|
||||||
```
|
|
||||||
|
|
||||||
## 提交信息规范
|
|
||||||
|
|
||||||
建议使用清晰的提交信息,例如:
|
|
||||||
|
|
||||||
```
|
|
||||||
- "Add new feature: radar data upload"
|
|
||||||
- "Fix bug: WiFi connection timeout"
|
|
||||||
- "Update documentation: README.md"
|
|
||||||
- "Refactor: improve code structure"
|
|
||||||
- "Optimize: reduce memory usage"
|
|
||||||
```
|
|
||||||
|
|
||||||
## 注意事项
|
|
||||||
|
|
||||||
1. **提交前检查**: 使用 `git status` 查看要提交的文件
|
|
||||||
2. **合理提交**: 频繁提交,每次提交一个完整的功能或修复
|
|
||||||
3. **提交信息**: 使用清晰、简洁的提交信息
|
|
||||||
4. **推送前拉取**: 推送前先 `git pull` 避免冲突
|
|
||||||
5. **敏感信息**: 不要提交密码、密钥等敏感信息
|
|
||||||
|
|
||||||
## 快捷别名(可选)
|
|
||||||
|
|
||||||
如果经常使用 Git,可以在 PowerShell 配置文件中添加别名:
|
|
||||||
|
|
||||||
```powershell
|
|
||||||
# 在 PowerShell 配置文件中添加
|
|
||||||
function gs { & "C:\Program Files\Git\bin\git.exe" status $args }
|
|
||||||
function ga { & "C:\Program Files\Git\bin\git.exe" add $args }
|
|
||||||
function gc { & "C:\Program Files\Git\bin\git.exe" commit -m $args }
|
|
||||||
function gp { & "C:\Program Files\Git\bin\git.exe" push $args }
|
|
||||||
function gl { & "C:\Program Files\Git\bin\git.exe" pull $args }
|
|
||||||
```
|
|
||||||
|
|
||||||
使用示例:
|
|
||||||
```powershell
|
|
||||||
gs # git status
|
|
||||||
ga -A # git add -A
|
|
||||||
gc "update" # git commit -m "update"
|
|
||||||
gp # git push
|
|
||||||
```
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
@echo off
|
|
||||||
chcp 65001 >nul
|
|
||||||
echo ========================================
|
|
||||||
echo Git 上传脚本 - Rader_Success_5
|
|
||||||
echo ========================================
|
|
||||||
echo.
|
|
||||||
|
|
||||||
set GIT_PATH="C:\Program Files\Git\bin\git.exe"
|
|
||||||
set REMOTE_URL=http://lmhrt.cn:6771/ming/Rader_Success_5.git
|
|
||||||
|
|
||||||
echo [1/5] 检查 Git 状态...
|
|
||||||
%GIT_PATH% status
|
|
||||||
echo.
|
|
||||||
|
|
||||||
echo [2/5] 添加所有文件到暂存区...
|
|
||||||
%GIT_PATH% add -A
|
|
||||||
echo.
|
|
||||||
|
|
||||||
echo [3/5] 提交更改...
|
|
||||||
set /p commit_msg="请输入提交信息 (默认: Update project): "
|
|
||||||
if "%commit_msg%"=="" set commit_msg=Update project
|
|
||||||
%GIT_PATH% commit -m "%commit_msg%"
|
|
||||||
echo.
|
|
||||||
|
|
||||||
echo [4/5] 拉取远程代码...
|
|
||||||
%GIT_PATH% pull
|
|
||||||
echo.
|
|
||||||
|
|
||||||
echo [5/5] 推送到远程仓库...
|
|
||||||
%GIT_PATH% push
|
|
||||||
echo.
|
|
||||||
|
|
||||||
echo ========================================
|
|
||||||
echo 上传完成!
|
|
||||||
echo ========================================
|
|
||||||
echo.
|
|
||||||
pause
|
|
||||||
Reference in New Issue
Block a user