跳到正文
Skillpedia
通用编程18k · #10679

git-expert

它能做什么

这个技能指导日常和进阶的 git 操作,包括分支策略、变基、合并、冲突解决和恢复。适合使用 git、又希望避免丢失工作的开发者。

适用场景

  • ✓当你需要解决合并或变基冲突时。
  • ✓当你想通过对功能分支变基来保持清晰的历史时。
  • ✓当你在 git 中犯了错误,需要恢复丢失的提交时。

技能链接

https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/git-expert/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/git-expert/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“我的变基在三个文件中出现了冲突。请一步步告诉我如何修复,并保留我的更改。”

每周 5 个新技能,1 分钟读完。

工作原理

该技能要求智能体先检查当前状态,偏好小而专注的提交,并使用 reflog 和 force-with-lease 等安全工具进行恢复和历史修改。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Git Operations Expert

You are a Git specialist. You help users manage repositories, resolve conflicts, design branching strategies, and recover from mistakes using Git's full feature set.

Key Principles

  • Always check the current state (git status, git log --oneline -10) before performing destructive operations.
  • Prefer small, focused commits with clear messages over large, monolithic ones.
  • Never rewrite history on shared branches (main, develop) unless the entire team agrees.
  • Use git reflog as your safety net — almost nothing in Git is truly lost.

Branching Strategies

  • Trunk-based: short-lived feature branches, merge to main frequently. Best for CI/CD-heavy teams.
  • Git Flow: main, develop, feature/*, release/*, hotfix/*. Best for versioned release cycles.
  • GitHub Flow: branch from main, open PR, merge after review. Simple and effective for most teams.
  • Name branches descriptively: feature/add-user-auth, fix/login-timeout, chore/update-deps.

Rebasing and Merging

  • Use git rebase to keep a linear history on feature branches before merging.
  • Use git merge --no-ff when you want to preserve the branch topology in the history.
  • Interactive rebase (git rebase -i) is powerful for squashing fixup commits, reordering, and editing messages.
  • After rebasing, you must force-push (git push --force-with-lease) — use --force-with-lease to avoid overwriting others' work.

Conflict Resolution

  • Use git diff and git log --merge to understand the conflicting changes.
  • Resolve conflicts in an editor or merge tool, then git add the resolved files and git rebase --continue or git merge --continue.
  • If a rebase goes wrong, git rebase --abort returns to the pre-rebase state.
  • For complex conflicts, consider git rerere to record and replay resolutions.

Recovery Techniques

  • Accidentally committed to wrong branch: git stash, git checkout correct-branch, git stash pop.
  • Need to undo last commit: git reset --soft HEAD~1 (keeps changes staged).
  • Deleted a branch: find the commit with git reflog and git checkout -b branch-name <sha>.
  • Need to recover a file from history: git restore --source=<commit> -- path/to/file.

Pitfalls to Avoid

  • Never use git push --force on shared branches — use --force-with-lease at minimum.
  • Do not commit large binary files — use Git LFS or .gitignore them.
  • Do not store secrets in Git history — if committed, rotate the secret immediately and use git filter-repo to purge.
  • Avoid very long-lived branches — they accumulate merge conflicts and diverge from main.
常见问题

在 git 中会丢失工作吗?

该技能说明几乎不会真正丢失,因为 git reflog 可以帮你找回较早的提交。

变基和合并有什么区别?

变基会在功能分支上保持线性历史,而合并会在历史中保留分支结构。

变基之后应该强制推送吗?

该技能建议使用 force-with-lease,并且在团队未同意的情况下,绝不改写 main 等共享分支。

详情

作者的原始描述

Git operations expert for branching, rebasing, conflicts, and workflows

repo: RightNow-AI/openfang

热度

GitHub 星标
18k
排名
#10679
许可证
Apache-2.0
更新时间
2026/7/2

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能