update: 2026-02-17 17:42:11

This commit is contained in:
2026-02-17 17:42:11 +08:00
parent e8d607c602
commit e78e33731b
2 changed files with 46 additions and 23 deletions

View File

@@ -11,7 +11,8 @@
## 2) 功能清单 ## 2) 功能清单
- [x] 灵活目录选择(启动时可管理任意仓库) - [x] 灵活目录选择(启动时可管理任意仓库)
- [x] 初始化仓库(创建分支、生成 `.gitignore` - [x] 初始化仓库(创建分支、生成 `.gitignore`
- [x] 提交并推送(含多远程选择,默认信息时间戳 - [x] 提交更改(提交到本地仓库
- [x] 推送更改(推送到远程仓库,支持多远程选择)
- [x] 从远程拉取 - [x] 从远程拉取
- [x] 远程仓库管理GitHub / GiteaSSH 优先) - [x] 远程仓库管理GitHub / GiteaSSH 优先)
- [x] 状态查看(工作区状态 + 最近提交) - [x] 状态查看(工作区状态 + 最近提交)
@@ -61,20 +62,22 @@ python3 quickgit.py
- 主菜单(含永久提示): - 主菜单(含永久提示):
``` ```
[1] 初始化Git仓库 [1] 初始化Git仓库
[2] 提交并推送更改 [2] 提交更改到本地
[3] 远程仓库拉取 [3] 推送到远程仓库
[4] 查看仓库状态 [4] 从远程仓库拉取
[5] 管理远程仓库 [5] 查看仓库状态
[6] 退出程序 [6] 管理远程仓库
[7] 退出程序
[*] 提交代码前建议先拉取最新代码,减少代码冲突 [*] 提交代码前建议先拉取最新代码,减少代码冲突
[*] 使用SSH进行Git提交更方便快捷和安全 [*] 使用SSH进行Git提交更方便快捷和安全
``` ```
## 6) 常用操作示例 ## 6) 常用操作示例
- 初始化仓库:选择目录 → 选 1 → 自动创建 `.gitignore`(含前端/后端通用规则)并尝试首提。 - 初始化仓库:选择目录 → 选 1 → 自动创建 `.gitignore`(含前端/后端通用规则)并尝试首提。
- 提交并推送:选 2 → 查看更改 → 输入提交信息(留空自动填入时间戳)→ 选择远程(可多选) - 提交更改:选 2 → 查看更改 → 输入提交信息(留空自动填入时间戳)→ 提交到本地仓库
- 拉取更新:选 3 → 选择远程 → 拉取当前分支 - 推送更改:选 3 → 选择远程(可多选)→ 推送到远程仓库
- 远程管理:选 5支持添加/删除远程URL 模板 - 拉取更新:选 4选择远程 → 拉取当前分支。
- 远程管理:选 6 → 支持添加/删除远程URL 模板
- GitHub: `git@github.com:shumengya/{repo}.git` - GitHub: `git@github.com:shumengya/{repo}.git`
- Gitea : `ssh://git@git.shumengya.top:8022/{user}/{repo}.git` - Gitea : `ssh://git@git.shumengya.top:8022/{user}/{repo}.git`

View File

@@ -90,11 +90,12 @@ class GitManagerUI:
print(f"{Colors.CYAN}{'-' * 60}{Colors.ENDC}") print(f"{Colors.CYAN}{'-' * 60}{Colors.ENDC}")
OutputFormatter.menu_item(1, "初始化Git仓库") OutputFormatter.menu_item(1, "初始化Git仓库")
OutputFormatter.menu_item(2, "提交并推送更改") OutputFormatter.menu_item(2, "提交更改到本地")
OutputFormatter.menu_item(3, "远程仓库拉取") OutputFormatter.menu_item(3, "推送到远程仓库")
OutputFormatter.menu_item(4, "查看仓库状态") OutputFormatter.menu_item(4, "从远程仓库拉取")
OutputFormatter.menu_item(5, "管理远程仓库") OutputFormatter.menu_item(5, "查看仓库状态")
OutputFormatter.menu_item(6, "退出程序") OutputFormatter.menu_item(6, "管理远程仓库")
OutputFormatter.menu_item(7, "退出程序")
print(f"{Colors.CYAN}{'-' * 60}{Colors.ENDC}") print(f"{Colors.CYAN}{'-' * 60}{Colors.ENDC}")
# 显示永久提示 # 显示永久提示
@@ -110,9 +111,9 @@ class GitManagerUI:
# 配置远程仓库 # 配置远程仓库
self.remote_mgr.configure_remotes_interactive() self.remote_mgr.configure_remotes_interactive()
def handle_commit_and_push(self): def handle_commit(self):
"""处理提交并推送""" """处理提交到本地"""
OutputFormatter.header("提交并推送更改") OutputFormatter.header("提交更改到本地")
if not self.git_ops.is_git_repo(): if not self.git_ops.is_git_repo():
OutputFormatter.error("当前目录不是Git仓库请先初始化") OutputFormatter.error("当前目录不是Git仓库请先初始化")
@@ -144,9 +145,26 @@ class GitManagerUI:
if not self.git_ops.commit(commit_msg or ""): if not self.git_ops.commit(commit_msg or ""):
return return
OutputFormatter.tip("提交成功如需推送到远程仓库请选择菜单选项3")
def handle_push(self):
"""处理推送到远程"""
OutputFormatter.header("推送到远程仓库")
if not self.git_ops.is_git_repo():
OutputFormatter.error("当前目录不是Git仓库请先初始化")
return
# 检查是否有提交可推送
OutputFormatter.status('running', "检查待推送的提交...")
# 推送到远程仓库 # 推送到远程仓库
selected_remotes = self.remote_mgr.select_remote_for_push() selected_remotes = self.remote_mgr.select_remote_for_push()
if not selected_remotes:
OutputFormatter.warning("未选择远程仓库")
return
for remote in selected_remotes: for remote in selected_remotes:
self.git_ops.push(remote) self.git_ops.push(remote)
@@ -223,21 +241,23 @@ class GitManagerUI:
self.show_main_menu() self.show_main_menu()
choice = InputValidator.get_choice( choice = InputValidator.get_choice(
f"{Colors.BRIGHT_MAGENTA}>> 请输入选项 [1-6]: {Colors.ENDC}", f"{Colors.BRIGHT_MAGENTA}>> 请输入选项 [1-7]: {Colors.ENDC}",
range(1, 7) range(1, 8)
) )
if choice == 1: if choice == 1:
self.handle_init_repo() self.handle_init_repo()
elif choice == 2: elif choice == 2:
self.handle_commit_and_push() self.handle_commit()
elif choice == 3: elif choice == 3:
self.handle_pull() self.handle_push()
elif choice == 4: elif choice == 4:
self.handle_show_status() self.handle_pull()
elif choice == 5: elif choice == 5:
self.handle_manage_remotes() self.handle_show_status()
elif choice == 6: elif choice == 6:
self.handle_manage_remotes()
elif choice == 7:
print(f"\n{Colors.BRIGHT_GREEN}{'=' * 60}") print(f"\n{Colors.BRIGHT_GREEN}{'=' * 60}")
print(f"{Colors.BRIGHT_GREEN}{Colors.BOLD} 感谢使用QuickGit祝您工作愉快{Colors.ENDC}") print(f"{Colors.BRIGHT_GREEN}{Colors.BOLD} 感谢使用QuickGit祝您工作愉快{Colors.ENDC}")
print(f"{Colors.BRIGHT_GREEN}{'=' * 60}{Colors.ENDC}\n") print(f"{Colors.BRIGHT_GREEN}{'=' * 60}{Colors.ENDC}\n")