Files
recommend/README_GIT_PUSH.md
赵杰 Jie Zhao (雄狮汽车科技) 7ab87e8f15 优化注册功能
2025-11-03 12:29:32 +08:00

183 lines
4.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Git 自动上传脚本使用指南
本目录提供了三个版本的 Git 自动上传脚本,适用于不同操作系统。
## 📋 脚本说明
### 1. `git_push.sh` - Linux/Mac Bash 脚本
适用于 Linux 和 MacOS 系统。
**使用方法:**
```bash
# 给脚本添加执行权限(首次使用)
chmod +x git_push.sh
# 基本使用(交互式输入提交信息)
./git_push.sh
# 直接指定提交信息
./git_push.sh "feat: 添加新功能"
```
### 2. `git_push.bat` - Windows 批处理脚本
适用于 Windows 系统。
**使用方法:**
```cmd
# 基本使用(交互式输入提交信息)
git_push.bat
# 直接指定提交信息
git_push.bat "feat: 添加新功能"
```
### 3. `git_push.py` - Python 跨平台脚本(推荐)
适用于所有操作系统Windows、Linux、Mac需要 Python 3.6+。
**使用方法:**
```bash
# 基本使用(交互式输入提交信息)
python git_push.py
# 直接指定提交信息
python git_push.py "feat: 添加新功能"
# 多个单词的提交信息
python git_push.py "feat: 添加新功能和修复bug"
```
## 🚀 功能特性
所有脚本都包含以下功能:
1. **自动检测 Git 仓库**:检查当前目录是否为 Git 仓库
2. **显示更改状态**:显示将要提交的文件
3. **交互式确认**:在提交前确认操作
4. **智能提交信息**
- 可以直接通过命令行参数指定
- 也可以交互式输入
- 默认提供带时间戳的提交信息
5. **自动添加文件**:自动添加所有更改的文件
6. **错误处理**:友好的错误提示和处理
7. **颜色输出**支持彩色输出Python 版本)
## 📝 使用示例
### 示例 1基本使用
```bash
# Linux/Mac
./git_push.sh
# Windows
git_push.bat
# Python跨平台
python git_push.py
```
脚本会:
1. 显示当前更改的文件
2. 询问是否继续
3. 请求输入提交信息(或使用默认)
4. 自动添加、提交并推送
### 示例 2指定提交信息
```bash
# Linux/Mac
./git_push.sh "fix: 修复用户注册bug"
# Windows
git_push.bat "fix: 修复用户注册bug"
# Python
python git_push.py "fix: 修复用户注册bug"
```
### 示例 3提交多个文件的更改
```bash
# 脚本会自动检测所有更改的文件
./git_push.sh "feat: 添加Docker支持和优化内存配置"
```
## ⚙️ 配置说明
### 默认分支
脚本会自动检测当前分支并使用该分支进行推送。
### 远程仓库
确保已配置远程仓库:
```bash
# 查看远程仓库
git remote -v
# 如果未配置,添加远程仓库
git remote add origin <your-repo-url>
```
### 身份验证
如果推送时遇到身份验证问题:
1. **HTTPS 方式**
- 需要输入用户名和密码(或访问令牌)
- 可以配置凭证助手避免每次输入:
```bash
git config --global credential.helper store
```
2. **SSH 方式**
- 配置 SSH 密钥更安全
- 将远程 URL 改为 SSH 格式:
```bash
git remote set-url origin git@github.com:username/repo.git
```
## 🔧 故障排除
### 问题 1权限不足Linux/Mac
```bash
# 解决方案:添加执行权限
chmod +x git_push.sh
```
### 问题 2Python 脚本无法运行
```bash
# 检查 Python 版本
python --version # 需要 Python 3.6+
# 如果系统中有多个 Python 版本
python3 git_push.py
```
### 问题 3推送失败认证问题
- 检查远程仓库地址是否正确
- 确认已配置 SSH 密钥或访问令牌
- 可以手动执行 `git push origin <branch>` 测试
### 问题 4没有需要提交的更改
- 脚本会检测是否有未提交的更改
- 如果没有更改,可以选择拉取远程更新
## 💡 建议
1. **推荐使用 Python 版本**`git_push.py`
- 跨平台兼容性最好
- 错误处理更完善
- 支持彩色输出
2. **提交信息规范**
- 使用规范的提交信息格式,例如:
- `feat: 添加新功能`
- `fix: 修复bug`
- `docs: 更新文档`
- `chore: 更新配置`
- `refactor: 代码重构`
3. **定期提交**
- 建议频繁提交小的更改
- 避免一次性提交大量更改
## 📚 相关文档
- [Git 官方文档](https://git-scm.com/doc)
- [提交信息规范](https://www.conventionalcommits.org/)