Compare commits
4 Commits
b75dee4536
...
e8d607c602
| Author | SHA1 | Date | |
|---|---|---|---|
| e8d607c602 | |||
| e8697e3676 | |||
| d6fbdf16e3 | |||
| 6973a327e4 |
@@ -241,7 +241,7 @@ OutputFormatter.menu_item(1, "Option") # [1] Menu item
|
||||
### SSH Configuration
|
||||
|
||||
- **GitHub:** `git@github.com:shumengya/{repo}.git`
|
||||
- **Gitea:** `ssh://git@repo.shumengya.top:8022/{user}/{repo}.git`
|
||||
- **Gitea:** `ssh://git@git.shumengya.top:8022/{user}/{repo}.git`
|
||||
|
||||
All remote operations use SSH (no HTTPS).
|
||||
|
||||
|
||||
122
CLAUDE.md
Normal file
122
CLAUDE.md
Normal file
@@ -0,0 +1,122 @@
|
||||
# CLAUDE.md
|
||||
|
||||
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
||||
|
||||
## Project Overview
|
||||
|
||||
QuickGit (萌芽一键Git管理工具) is a Python CLI tool that simplifies Git operations through an interactive menu interface. It supports managing multiple Git repositories, handles both GitHub and Gitea remotes, and provides cross-platform compatibility (Windows, Linux, macOS).
|
||||
|
||||
## Running the Application
|
||||
|
||||
**Windows:**
|
||||
```bash
|
||||
run.bat # Recommended - sets UTF-8 encoding
|
||||
python quickgit.py # Direct execution
|
||||
```
|
||||
|
||||
**Linux/macOS:**
|
||||
```bash
|
||||
./run.sh # Recommended (requires chmod +x run.sh first time)
|
||||
python3 quickgit.py # Direct execution
|
||||
```
|
||||
|
||||
The tool is interactive - no command-line arguments needed. On startup, it prompts for a Git repository directory to manage.
|
||||
|
||||
## Architecture
|
||||
|
||||
The codebase follows a modular design with clear separation of concerns:
|
||||
|
||||
### Module Hierarchy
|
||||
|
||||
```
|
||||
quickgit.py (entry point)
|
||||
└── ui.py (GitManagerUI)
|
||||
├── git_operations.py (GitOperations)
|
||||
├── remote_manager.py (RemoteManager)
|
||||
├── utils.py (CommandExecutor, OutputFormatter, InputValidator, PlatformUtils)
|
||||
└── config.py (Config)
|
||||
```
|
||||
|
||||
### Key Design Patterns
|
||||
|
||||
**1. Utility Classes Pattern** (`utils.py`)
|
||||
- `CommandExecutor`: Centralized subprocess execution with UTF-8 handling
|
||||
- `OutputFormatter`: Consistent colored console output (success/error/info/warning/step)
|
||||
- `InputValidator`: User input validation and directory path handling
|
||||
- `PlatformUtils`: Cross-platform operations (clear screen, path normalization, platform detection)
|
||||
- `Colors`: ANSI color code definitions
|
||||
|
||||
**2. Operations Layer** (`git_operations.py`)
|
||||
- `GitOperations` class manages all Git commands
|
||||
- Maintains working directory state (`self.current_dir`)
|
||||
- All Git operations use `CommandExecutor` for consistency
|
||||
- Methods return `tuple[bool, str]` for success status and output
|
||||
|
||||
**3. Remote Management** (`remote_manager.py`)
|
||||
- Handles GitHub and Gitea remote repository configuration
|
||||
- GitHub format: `git@github.com:shumengya/{repo}.git`
|
||||
- Gitea format: `ssh://git@git.shumengya.top:8022/{user}/{repo}.git`
|
||||
- Manages multiple remotes per repository
|
||||
|
||||
**4. Configuration** (`config.py`)
|
||||
- Centralized configuration in `Config` class
|
||||
- Gitea server: `git.shumengya.top:8022`
|
||||
- GitHub user: `shumengya`
|
||||
- Default branch: `main`
|
||||
- Includes comprehensive `.gitignore` template for Node.js, Go, Python projects
|
||||
|
||||
### Cross-Platform Considerations
|
||||
|
||||
The codebase handles platform differences through `PlatformUtils`:
|
||||
- Path normalization with `os.path.expanduser()` and `os.path.normpath()`
|
||||
- Platform detection: `is_windows()`, `is_linux()`, `is_mac()`
|
||||
- Clear screen: `cls` (Windows) vs `clear` (Unix)
|
||||
- Python command: `python` (Windows) vs `python3` (Unix)
|
||||
- UTF-8 encoding explicitly set in subprocess calls
|
||||
|
||||
### State Management
|
||||
|
||||
- `GitOperations` maintains `self.current_dir` for the working directory
|
||||
- Directory can be changed via `change_directory()` method
|
||||
- All Git commands execute in the context of `self.current_dir`
|
||||
- UI layer (`ui.py`) orchestrates state between operations and remote management
|
||||
|
||||
## Important Implementation Details
|
||||
|
||||
**Commit Message Format:**
|
||||
- Default format: `update: YYYY-MM-DD HH:MM:SS` (see `git_operations.py:145`)
|
||||
- Generated using `datetime.now().strftime('%Y-%m-%d %H:%M:%S')`
|
||||
|
||||
**Git Initialization Workflow:**
|
||||
1. Run `git init`
|
||||
2. Create `main` branch with `git checkout -b main`
|
||||
3. Create `.gitignore` from template
|
||||
4. Initial commit with message "first commit"
|
||||
|
||||
**Push Strategy:**
|
||||
- First attempts direct push: `git push {remote} {branch}`
|
||||
- If fails, retries with upstream: `git push -u {remote} {branch}`
|
||||
- This handles first-time pushes to new remotes
|
||||
|
||||
**Subprocess Execution:**
|
||||
- All commands use `shell=True` for compatibility
|
||||
- UTF-8 encoding with `errors='ignore'` for robustness
|
||||
- Captures both stdout and stderr combined
|
||||
- Returns `(success: bool, output: str)` tuple
|
||||
|
||||
## Configuration Customization
|
||||
|
||||
To modify default settings, edit `quickgit/config.py`:
|
||||
- `GITEA_HOST` and `GITEA_PORT`: Gitea server details
|
||||
- `GITHUB_USER`: Default GitHub username
|
||||
- `DEFAULT_BRANCH`: Default branch name (currently "main")
|
||||
- `GITIGNORE_TEMPLATE`: Template for auto-generated .gitignore files
|
||||
|
||||
## Testing Considerations
|
||||
|
||||
When testing or modifying Git operations:
|
||||
- Test with both existing and non-existing repositories
|
||||
- Verify cross-platform path handling (Windows backslashes vs Unix forward slashes)
|
||||
- Test with repositories that have/don't have remotes configured
|
||||
- Verify UTF-8 handling for commit messages with non-ASCII characters
|
||||
- Test the push retry logic (direct push → upstream push fallback)
|
||||
350
GitHub_SSH_故障排查.md
Normal file
350
GitHub_SSH_故障排查.md
Normal file
@@ -0,0 +1,350 @@
|
||||
# GitHub SSH 连接问题诊断与解决方案
|
||||
|
||||
## 问题现象
|
||||
|
||||
```
|
||||
Connection closed by 198.18.0.66 port 22
|
||||
fatal: Could not read from remote repository.
|
||||
```
|
||||
|
||||
这个错误表明 SSH 连接被关闭,可能的原因包括:
|
||||
1. SSH 密钥未正确配置
|
||||
2. SSH 密钥未添加到 GitHub
|
||||
3. 网络问题或代理设置
|
||||
4. SSH 配置文件问题
|
||||
|
||||
---
|
||||
|
||||
## 诊断步骤
|
||||
|
||||
### 第 1 步:检查 SSH 密钥是否存在
|
||||
|
||||
**Windows:**
|
||||
```bash
|
||||
dir %USERPROFILE%\.ssh
|
||||
```
|
||||
|
||||
**Linux/macOS:**
|
||||
```bash
|
||||
ls -la ~/.ssh
|
||||
```
|
||||
|
||||
**应该看到:**
|
||||
- `id_rsa` 和 `id_rsa.pub` (RSA 密钥)
|
||||
- 或 `id_ed25519` 和 `id_ed25519.pub` (Ed25519 密钥,推荐)
|
||||
|
||||
---
|
||||
|
||||
### 第 2 步:如果没有 SSH 密钥,生成新密钥
|
||||
|
||||
**推荐方式 (Ed25519):**
|
||||
```bash
|
||||
ssh-keygen -t ed25519 -C "your_email@example.com"
|
||||
```
|
||||
|
||||
**传统方式 (RSA):**
|
||||
```bash
|
||||
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
|
||||
```
|
||||
|
||||
**执行过程:**
|
||||
```
|
||||
Generating public/private ed25519 key pair.
|
||||
Enter file in which to save the key (/home/user/.ssh/id_ed25519): [直接回车]
|
||||
Enter passphrase (empty for no passphrase): [可以直接回车或输入密码]
|
||||
Enter same passphrase again: [重复密码]
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 第 3 步:查看公钥内容
|
||||
|
||||
**Windows:**
|
||||
```bash
|
||||
type %USERPROFILE%\.ssh\id_ed25519.pub
|
||||
# 或
|
||||
type %USERPROFILE%\.ssh\id_rsa.pub
|
||||
```
|
||||
|
||||
**Linux/macOS:**
|
||||
```bash
|
||||
cat ~/.ssh/id_ed25519.pub
|
||||
# 或
|
||||
cat ~/.ssh/id_rsa.pub
|
||||
```
|
||||
|
||||
**复制输出的完整内容**,类似:
|
||||
```
|
||||
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIM... your_email@example.com
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 第 4 步:添加公钥到 GitHub
|
||||
|
||||
1. **登录 GitHub**: https://github.com
|
||||
2. **打开设置**: 点击右上角头像 → Settings
|
||||
3. **SSH 和 GPG 密钥**: 左侧菜单 → SSH and GPG keys
|
||||
4. **添加新密钥**: 点击 "New SSH key" 按钮
|
||||
5. **填写信息:**
|
||||
- Title: 给密钥起个名字(如:My Windows PC)
|
||||
- Key: 粘贴第3步复制的公钥内容
|
||||
6. **保存**: 点击 "Add SSH key"
|
||||
|
||||
---
|
||||
|
||||
### 第 5 步:测试 SSH 连接
|
||||
|
||||
```bash
|
||||
ssh -T git@github.com
|
||||
```
|
||||
|
||||
**成功的输出:**
|
||||
```
|
||||
Hi username! You've successfully authenticated, but GitHub does not provide shell access.
|
||||
```
|
||||
|
||||
**如果仍然失败,继续下一步...**
|
||||
|
||||
---
|
||||
|
||||
## 常见问题与解决方案
|
||||
|
||||
### 问题 1: Connection closed by 198.18.0.66
|
||||
|
||||
这个 IP 地址 `198.18.0.66` 不是 GitHub 的官方 IP,可能是:
|
||||
- 代理服务器
|
||||
- VPN
|
||||
- 公司网络的网关
|
||||
|
||||
**解决方案:检查代理设置**
|
||||
|
||||
#### 方案 A: 配置 Git 使用代理
|
||||
|
||||
如果您在使用代理,需要配置:
|
||||
|
||||
```bash
|
||||
# HTTP 代理
|
||||
git config --global http.proxy http://proxy_server:port
|
||||
git config --global https.proxy https://proxy_server:port
|
||||
|
||||
# SOCKS5 代理
|
||||
git config --global http.proxy socks5://proxy_server:port
|
||||
```
|
||||
|
||||
#### 方案 B: 取消代理设置
|
||||
|
||||
```bash
|
||||
git config --global --unset http.proxy
|
||||
git config --global --unset https.proxy
|
||||
```
|
||||
|
||||
#### 方案 C: 为 SSH 配置代理
|
||||
|
||||
创建或编辑 `~/.ssh/config` 文件:
|
||||
|
||||
**Windows:** `C:\Users\YourName\.ssh\config`
|
||||
**Linux/macOS:** `~/.ssh/config`
|
||||
|
||||
```
|
||||
Host github.com
|
||||
HostName github.com
|
||||
User git
|
||||
# 如果使用 HTTP 代理
|
||||
ProxyCommand connect -H proxy_server:port %h %p
|
||||
# 如果使用 SOCKS5 代理
|
||||
# ProxyCommand connect -S proxy_server:port %h %p
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 问题 2: Permission denied (publickey)
|
||||
|
||||
**原因:** SSH 密钥未被识别
|
||||
|
||||
**解决方案:**
|
||||
|
||||
1. **启动 SSH Agent:**
|
||||
```bash
|
||||
# Windows (Git Bash)
|
||||
eval "$(ssh-agent -s)"
|
||||
|
||||
# Linux/macOS
|
||||
eval "$(ssh-agent -s)"
|
||||
```
|
||||
|
||||
2. **添加私钥到 SSH Agent:**
|
||||
```bash
|
||||
ssh-add ~/.ssh/id_ed25519
|
||||
# 或
|
||||
ssh-add ~/.ssh/id_rsa
|
||||
```
|
||||
|
||||
3. **再次测试连接:**
|
||||
```bash
|
||||
ssh -T git@github.com
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 问题 3: 防火墙阻止 SSH 端口 22
|
||||
|
||||
**解决方案 A: 使用 HTTPS 代替 SSH**
|
||||
|
||||
修改远程仓库 URL:
|
||||
```bash
|
||||
# 查看当前 URL
|
||||
git remote -v
|
||||
|
||||
# 修改为 HTTPS
|
||||
git remote set-url origin https://github.com/shumengya/QuickGit.git
|
||||
```
|
||||
|
||||
**缺点:** 每次推送需要输入用户名和密码(或 Token)
|
||||
|
||||
**解决方案 B: 使用 SSH over HTTPS (端口 443)**
|
||||
|
||||
编辑 `~/.ssh/config`:
|
||||
```
|
||||
Host github.com
|
||||
HostName ssh.github.com
|
||||
Port 443
|
||||
User git
|
||||
```
|
||||
|
||||
测试:
|
||||
```bash
|
||||
ssh -T -p 443 git@ssh.github.com
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 问题 4: SSH 密钥格式错误
|
||||
|
||||
**原因:** Windows 换行符问题或复制时引入了额外字符
|
||||
|
||||
**解决方案:**
|
||||
|
||||
1. **重新生成密钥**(推荐)
|
||||
2. **或确保公钥完整且格式正确**
|
||||
|
||||
---
|
||||
|
||||
## QuickGit 用户的完整解决流程
|
||||
|
||||
### 步骤 1: 生成 SSH 密钥
|
||||
|
||||
```bash
|
||||
# Windows (Git Bash 或 PowerShell)
|
||||
ssh-keygen -t ed25519 -C "shumengya@example.com"
|
||||
|
||||
# 一路回车即可
|
||||
```
|
||||
|
||||
### 步骤 2: 复制公钥
|
||||
|
||||
```bash
|
||||
# Windows
|
||||
type %USERPROFILE%\.ssh\id_ed25519.pub
|
||||
|
||||
# Linux/macOS
|
||||
cat ~/.ssh/id_ed25519.pub
|
||||
```
|
||||
|
||||
### 步骤 3: 添加到 GitHub
|
||||
|
||||
1. 访问 https://github.com/settings/keys
|
||||
2. 点击 "New SSH key"
|
||||
3. 粘贴公钥,保存
|
||||
|
||||
### 步骤 4: 测试连接
|
||||
|
||||
```bash
|
||||
ssh -T git@github.com
|
||||
```
|
||||
|
||||
**期望输出:**
|
||||
```
|
||||
Hi shumengya! You've successfully authenticated...
|
||||
```
|
||||
|
||||
### 步骤 5: 在 QuickGit 中重新配置远程仓库
|
||||
|
||||
如果之前的远程仓库配置有问题:
|
||||
|
||||
```bash
|
||||
# 删除旧的 github 远程仓库
|
||||
git remote remove github
|
||||
|
||||
# 重新添加
|
||||
git remote add github git@github.com:shumengya/QuickGit.git
|
||||
|
||||
# 验证
|
||||
git remote -v
|
||||
```
|
||||
|
||||
### 步骤 6: 使用 QuickGit 推送
|
||||
|
||||
1. 启动 QuickGit
|
||||
2. 选择 `[2] 提交并推送更改`
|
||||
3. 选择推送到 `github`
|
||||
|
||||
---
|
||||
|
||||
## 调试命令
|
||||
|
||||
如果问题仍然存在,使用以下命令获取详细信息:
|
||||
|
||||
```bash
|
||||
# 详细模式测试 SSH 连接
|
||||
ssh -vT git@github.com
|
||||
|
||||
# 查看 Git 配置
|
||||
git config --list
|
||||
|
||||
# 查看远程仓库配置
|
||||
git remote -v
|
||||
|
||||
# 手动推送(查看详细错误)
|
||||
git push -v github main
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 快速修复:改用 HTTPS
|
||||
|
||||
如果 SSH 问题难以解决,可以临时使用 HTTPS:
|
||||
|
||||
```bash
|
||||
# 修改远程仓库 URL
|
||||
git remote set-url github https://github.com/shumengya/QuickGit.git
|
||||
|
||||
# 推送(需要输入用户名和密码/Token)
|
||||
git push github main
|
||||
```
|
||||
|
||||
**注意:** HTTPS 方式需要:
|
||||
- GitHub 用户名
|
||||
- Personal Access Token(不能使用密码)
|
||||
|
||||
**生成 Token:**
|
||||
1. GitHub → Settings → Developer settings → Personal access tokens → Tokens (classic)
|
||||
2. Generate new token
|
||||
3. 勾选 `repo` 权限
|
||||
4. 复制 Token(只显示一次)
|
||||
|
||||
---
|
||||
|
||||
## 总结
|
||||
|
||||
**推荐解决方案顺序:**
|
||||
|
||||
1. ✅ 生成 SSH 密钥
|
||||
2. ✅ 添加公钥到 GitHub
|
||||
3. ✅ 测试 SSH 连接
|
||||
4. ✅ 配置 SSH Agent(如果需要)
|
||||
5. ⚠️ 检查代理设置(如果在公司网络)
|
||||
6. 🔄 最后选择:使用 HTTPS 作为备用方案
|
||||
|
||||
**最快的解决方法:**
|
||||
如果急需推送代码,先改用 HTTPS,之后再慢慢配置 SSH。
|
||||
289
README.md
289
README.md
@@ -1,81 +1,64 @@
|
||||
# QuickGit - 萌芽一键Git管理工具
|
||||
|
||||
一个简单易用的模块化Git命令行管理工具,让Git操作更加便捷高效。
|
||||
一个纯 Python 3.6+、零外部依赖的彩色 CLI 工具,用模块化方式把常用 Git 操作“一键化”,支持 Windows / Linux / macOS。
|
||||
|
||||
## 功能特性
|
||||
## 1) 项目简介与核心卖点
|
||||
- 模块化架构,功能职责清晰,易扩展。
|
||||
- 无三方依赖,直接随 Python 运行。
|
||||
- 跨平台路径与编码适配,默认分支 `main`。
|
||||
- 彩色输出 + ASCII 分隔线,兼顾可读性与兼容性。
|
||||
|
||||
- **灵活的目录管理** - 启动时可选择任意Git仓库目录进行管理
|
||||
- **一键初始化Git仓库** - 自动完成Git初始化、分支创建、.gitignore配置
|
||||
- **一键提交推送** - 快速提交代码并推送到远程仓库
|
||||
- **多仓库支持** - 同时支持GitHub和Gitea仓库管理
|
||||
- **远程仓库管理** - 便捷地添加、删除、查看远程仓库
|
||||
- **状态查看** - 快速查看仓库状态和提交历史
|
||||
- **彩色界面** - 友好的彩色控制台输出
|
||||
- **模块化设计** - 易于维护和扩展
|
||||
- **跨平台支持** - 完美兼容 Windows、Linux、macOS
|
||||
- **智能路径处理** - 自动处理不同平台的路径格式
|
||||
|
||||
## 项目结构
|
||||
## 2) 功能清单
|
||||
- [x] 灵活目录选择(启动时可管理任意仓库)
|
||||
- [x] 初始化仓库(创建分支、生成 `.gitignore`)
|
||||
- [x] 提交并推送(含多远程选择,默认信息时间戳)
|
||||
- [x] 从远程拉取
|
||||
- [x] 远程仓库管理(GitHub / Gitea,SSH 优先)
|
||||
- [x] 状态查看(工作区状态 + 最近提交)
|
||||
- [ ] 分支管理
|
||||
- [ ] 标签管理
|
||||
- [ ] 冲突解决辅助
|
||||
- [ ] 自定义配置文件
|
||||
- [ ] 批量处理多个仓库
|
||||
|
||||
## 3) 项目结构
|
||||
```
|
||||
QuickGit/
|
||||
├── quickgit/ # 核心模块
|
||||
│ ├── __init__.py # 包初始化
|
||||
│ ├── config.py # 配置模块
|
||||
│ ├── utils.py # 工具类(命令执行、输出格式化、输入验证、平台工具)
|
||||
│ ├── git_operations.py # Git操作模块
|
||||
│ ├── remote_manager.py # 远程仓库管理模块
|
||||
│ └── ui.py # UI交互模块
|
||||
├── quickgit.py # 主程序入口
|
||||
├── run.bat # Windows启动脚本
|
||||
├── run.sh # Linux/macOS启动脚本
|
||||
├── mengya_git_manager.py # 旧版单文件脚本(兼容保留)
|
||||
└── README.md # 项目文档
|
||||
│ ├── __init__.py
|
||||
│ ├── config.py # 常量与 .gitignore 模板
|
||||
│ ├── utils.py # 颜色、输出、命令执行、输入校验、平台工具
|
||||
│ ├── git_operations.py # init / add / commit / push / pull / status
|
||||
│ ├── remote_manager.py # 远程管理(GitHub/Gitea)
|
||||
│ └── ui.py # 交互与菜单
|
||||
├── quickgit.py # 主入口(模块化版本)
|
||||
├── run.bat # Windows 启动脚本(UTF-8)
|
||||
├── run.sh # Linux/macOS 启动脚本(需 chmod +x)
|
||||
├── mengya_git_manager.py # 旧版单文件脚本(兼容保留)
|
||||
└── README.md
|
||||
```
|
||||
|
||||
## 快速开始
|
||||
## 4) 快速开始
|
||||
前置要求:已安装 Git,Python 3.6+;已配置 SSH 密钥(推荐用 SSH 访问远程仓库)。
|
||||
|
||||
### 运行脚本
|
||||
|
||||
**Windows:**
|
||||
**Windows**
|
||||
```bash
|
||||
# 使用启动脚本(自动设置UTF-8编码)
|
||||
run.bat
|
||||
|
||||
# 或直接运行
|
||||
# 或
|
||||
python quickgit.py
|
||||
```
|
||||
|
||||
**Linux/macOS:**
|
||||
**Linux / macOS**
|
||||
```bash
|
||||
# 首次使用需要添加执行权限
|
||||
chmod +x run.sh
|
||||
|
||||
# 使用启动脚本(推荐)
|
||||
./run.sh
|
||||
|
||||
# 或直接运行
|
||||
# 或
|
||||
python3 quickgit.py
|
||||
```
|
||||
|
||||
**通用方式:**
|
||||
```bash
|
||||
# 新版模块化脚本(推荐)
|
||||
python quickgit.py
|
||||
|
||||
# 或使用旧版单文件脚本
|
||||
python mengya_git_manager.py
|
||||
```
|
||||
|
||||
### 主要功能菜单
|
||||
|
||||
**首次启动时:**
|
||||
- 选择要管理的Git仓库目录
|
||||
- 支持绝对路径和相对路径
|
||||
- 直接回车使用脚本所在目录
|
||||
- 自动验证目录是否存在
|
||||
|
||||
**主菜单选项:**
|
||||
## 5) 交互流程
|
||||
- 启动即要求选择工作目录:支持绝对/相对路径,直接回车使用脚本所在目录,自动校验目录存在。
|
||||
- 主菜单(含永久提示):
|
||||
```
|
||||
[1] 初始化Git仓库
|
||||
[2] 提交并推送更改
|
||||
@@ -83,173 +66,51 @@ python mengya_git_manager.py
|
||||
[4] 查看仓库状态
|
||||
[5] 管理远程仓库
|
||||
[6] 退出程序
|
||||
|
||||
小提示:
|
||||
[*] 提交代码前建议先拉取最新代码,减少代码冲突
|
||||
[*] 使用SSH进行Git提交更方便快捷和安全
|
||||
```
|
||||
|
||||
## 使用场景
|
||||
## 6) 常用操作示例
|
||||
- 初始化仓库:选择目录 → 选 1 → 自动创建 `.gitignore`(含前端/后端通用规则)并尝试首提。
|
||||
- 提交并推送:选 2 → 查看更改 → 输入提交信息(留空自动填入时间戳)→ 选择远程(可多选)。
|
||||
- 拉取更新:选 3 → 选择远程 → 拉取当前分支。
|
||||
- 远程管理:选 5 → 支持添加/删除远程;URL 模板
|
||||
- GitHub: `git@github.com:shumengya/{repo}.git`
|
||||
- Gitea : `ssh://git@git.shumengya.top:8022/{user}/{repo}.git`
|
||||
|
||||
### 场景0:选择工作目录
|
||||
## 7) 跨平台与终端要求
|
||||
- `run.bat` 自动设置 UTF-8;Windows 使用 `python` 命令。
|
||||
- `run.sh` 设置 `LANG/LC_ALL`,首次需 `chmod +x run.sh`;Linux/macOS 使用 `python3`。
|
||||
- 终端需支持 ANSI 颜色;仅使用 ASCII 符号,避免编码错位。
|
||||
|
||||
启动脚本后,首先会要求选择工作目录:
|
||||
## 8) 控制台输出规范
|
||||
- 分隔线宽度固定 60:`======` / `------` / `·····`。
|
||||
- 禁止使用 emoji 和 Unicode 盒线字符。
|
||||
- 颜色键值:成功绿、错误红、信息青、警告黄、标题青/品红。
|
||||
- 状态/提示图标:`[√] [×] [i] [!] [>] [*]`。
|
||||
|
||||
**Windows示例:**
|
||||
```
|
||||
请输入要管理的Git仓库目录 (回车使用当前目录: E:\Projects\MyApp):
|
||||
输入: C:\Users\YourName\project
|
||||
或: .\myproject (相对路径)
|
||||
或: 直接回车使用默认目录
|
||||
```
|
||||
## 9) 手动测试清单
|
||||
- 启动脚本:`run.bat`、`run.sh`、直接运行 `python/ python3 quickgit.py`。
|
||||
- 颜色与中文显示正常,分隔线对齐 60 列。
|
||||
- 初始化仓库、提交+推送、拉取、远程管理均可用。
|
||||
- 默认分支 `main`;`.gitignore` 自动写入成功。
|
||||
|
||||
**Linux/macOS示例:**
|
||||
```
|
||||
请输入要管理的Git仓库目录 (回车使用当前目录: /home/user/quickgit):
|
||||
输入: /home/yourname/project
|
||||
或: ./myproject (相对路径)
|
||||
或: ~/project (使用~表示用户目录)
|
||||
或: 直接回车使用默认目录
|
||||
```
|
||||
|
||||
### 场景1:初始化新项目
|
||||
|
||||
1. 运行脚本,输入项目目录路径(或直接回车使用当前目录)
|
||||
2. 选择 `1. 初始化Git仓库`
|
||||
3. 按提示配置GitHub或Gitea远程仓库
|
||||
4. 完成首次提交
|
||||
|
||||
### 场景2:提交代码更改
|
||||
|
||||
1. 运行脚本,选择要管理的Git仓库目录
|
||||
2. 选择 `2. 提交并推送更改`
|
||||
3. 输入提交信息(或使用默认信息)
|
||||
4. 选择推送到哪个远程仓库
|
||||
|
||||
### 场景3:拉取远程更新
|
||||
|
||||
1. 运行脚本,选择要管理的Git仓库目录
|
||||
2. 选择 `3. 从远程仓库拉取`
|
||||
3. 选择要拉取的远程仓库
|
||||
|
||||
### 场景4:管理多个项目
|
||||
|
||||
1. 每次运行脚本都可以选择不同的项目目录
|
||||
2. 无需在项目目录中运行脚本
|
||||
3. 一个工具管理所有Git项目
|
||||
|
||||
## 远程仓库配置
|
||||
|
||||
### GitHub配置
|
||||
|
||||
- 使用SSH方式连接
|
||||
- 格式:`git@github.com:shumengya/{仓库名}.git`
|
||||
|
||||
### Gitea配置
|
||||
|
||||
- 服务器地址:`repo.shumengya.top:8022`
|
||||
- 使用SSH方式连接
|
||||
- 格式:`ssh://git@repo.shumengya.top:8022/{用户名}/{仓库名}.git`
|
||||
|
||||
## .gitignore 支持
|
||||
|
||||
脚本自动创建的 `.gitignore` 文件支持以下项目类型:
|
||||
|
||||
- **Node.js/React** - node_modules/, build/, dist/
|
||||
- **Go** - *.exe, *.test, vendor/
|
||||
- **Python** - __pycache__/, venv/, *.pyc
|
||||
- **通用** - 日志文件、临时文件、IDE配置
|
||||
|
||||
## 系统要求
|
||||
|
||||
- **Python:** 3.6+ (Linux/macOS 使用 python3)
|
||||
- **Git:** 已安装并配置
|
||||
- **SSH密钥:** 已配置(用于远程仓库推送)
|
||||
- **操作系统:** Windows、Linux、macOS 均支持
|
||||
|
||||
### 平台特定说明
|
||||
|
||||
**Windows:**
|
||||
- 建议使用 `run.bat` 启动,自动配置UTF-8编码
|
||||
- 控制台需支持ANSI颜色代码(Windows 10+自带支持)
|
||||
|
||||
**Linux/macOS:**
|
||||
- 使用 `python3` 命令运行
|
||||
- 确保终端支持UTF-8编码和颜色显示
|
||||
- 首次使用 `run.sh` 需要添加执行权限:`chmod +x run.sh`
|
||||
|
||||
## 注意事项
|
||||
|
||||
1. 首次使用前请确保已配置Git用户信息:
|
||||
```bash
|
||||
git config --global user.name "你的名字"
|
||||
git config --global user.email "你的邮箱"
|
||||
```
|
||||
|
||||
2. 使用SSH方式连接需要提前配置SSH密钥
|
||||
|
||||
3. 推送到Gitea时请确保仓库已在服务器上创建
|
||||
|
||||
4. **重要提示:** 提交代码前建议先拉取最新代码,减少代码冲突
|
||||
- 先执行 `3. 从远程仓库拉取`
|
||||
- 再执行 `2. 提交并推送更改`
|
||||
|
||||
## 常见问题
|
||||
|
||||
**Q: 推送失败怎么办?**
|
||||
A: 请检查SSH密钥配置和远程仓库地址是否正确
|
||||
|
||||
**Q: 如何切换远程仓库?**
|
||||
A: 使用 `5. 管理远程仓库` 功能添加或删除远程仓库
|
||||
|
||||
**Q: 支持哪些Git操作?**
|
||||
A: 目前支持init、add、commit、push、pull等常用操作
|
||||
|
||||
## 模块说明
|
||||
|
||||
### config.py - 配置模块
|
||||
存储所有配置信息,包括Gitea服务器地址、GitHub用户名、.gitignore模板等。
|
||||
|
||||
### utils.py - 工具类模块
|
||||
- `Colors`: 控制台颜色定义
|
||||
- `CommandExecutor`: 命令执行器
|
||||
- `OutputFormatter`: 输出格式化器
|
||||
- `InputValidator`: 输入验证器
|
||||
- `PlatformUtils`: 跨平台工具(清屏、平台检测)
|
||||
|
||||
### git_operations.py - Git操作模块
|
||||
提供Git基本操作功能:
|
||||
- 初始化仓库
|
||||
- 检查状态
|
||||
- 添加/提交更改
|
||||
- 推送/拉取代码
|
||||
|
||||
### remote_manager.py - 远程仓库管理模块
|
||||
管理GitHub和Gitea远程仓库:
|
||||
- 添加/删除远程仓库
|
||||
- 查看远程仓库列表
|
||||
- 选择推送/拉取目标
|
||||
|
||||
### ui.py - UI交互模块
|
||||
处理用户界面和交互逻辑,整合所有功能模块。
|
||||
|
||||
## 开发计划
|
||||
## 10) 常见问题 / 故障排查
|
||||
- 推送失败:确认 SSH 密钥已添加且远程地址正确。
|
||||
- 终端乱码:设置 UTF-8(Windows 可 `chcp 65001`;Linux/macOS 确保 `LANG/LC_ALL` 为 UTF-8)。
|
||||
- 颜色不显示:使用支持 ANSI 的终端(Windows Terminal/PowerShell 等)。
|
||||
- 找不到 `python3`:在 Linux/macOS 安装或创建软链接;Windows 使用 `python`。
|
||||
|
||||
## 11) 路线图
|
||||
- [x] 模块化架构重构
|
||||
- [ ] 支持分支管理
|
||||
- [ ] 支持标签管理
|
||||
- [ ] 支持冲突解决辅助
|
||||
- [ ] 支持自定义配置文件
|
||||
- [ ] 支持批量操作多个仓库
|
||||
- [ ] 分支管理
|
||||
- [ ] 标签管理
|
||||
- [ ] 冲突解决辅助
|
||||
- [ ] 自定义配置文件
|
||||
- [ ] 批量操作多个仓库
|
||||
|
||||
## 许可证
|
||||
## 12) 许可证与作者
|
||||
- 许可证:MIT
|
||||
- 作者:shumengya
|
||||
|
||||
MIT License
|
||||
|
||||
## 作者
|
||||
|
||||
shumengya
|
||||
|
||||
---
|
||||
|
||||
**让Git操作更简单,让开发更高效!**
|
||||
让 Git 操作更简单,让开发更高效!
|
||||
|
||||
@@ -7,7 +7,7 @@ class Config:
|
||||
"""配置类"""
|
||||
|
||||
# Gitea服务器配置
|
||||
GITEA_HOST = "repo.shumengya.top"
|
||||
GITEA_HOST = "git.shumengya.top"
|
||||
GITEA_PORT = "8022"
|
||||
|
||||
# GitHub配置
|
||||
|
||||
Reference in New Issue
Block a user