CodeRoadMap
首页路线题库资源库文章社区
CodeRoadMap

程序员的学习成长路线图。内容免费开放,登录后可同步路线图与课时进度。

由 程序员柏风 独立维护 · 关于作者

学习

  • 路线图
  • 课程
  • 面试题
  • 文章
  • 我

更多

  • 资源
  • 社区
  • 关于作者
  • 内容说明

© 2026 CodeRoadMap

津ICP备2026012044号-1·津公网安备12011002026155号·coderoadmap@126.com
GitHub 协作进阶/课时/提交与历史
RawBlame
课时目录12 节

GitHub 协作进阶

  1. 01GitHub 路线图概览
  2. 02账号与 Profile
  3. 03仓库管理
  4. 04提交与历史
  5. 05分支与变基
  6. 06远程与 Fork
  7. 07Pull Request
  8. 08Issues 协作
  9. 09GitHub Actions
  10. 10组织与团队
  11. 11Pages 与静态站
  12. 12综合练习

提交与历史

committing-changes、viewing-commit-history、commit-messages。

30 分钟

提交与历史

每一次 commit 都是项目时间线上的检查点。GitHub 把本地历史可视化:Commits 列表、单行对比、blame、关联 PR。本课对应 git-github 路线图 的 committing-changes、viewing-commit-history、commit-messages。

git add / git commit 在 git-essentials 已练;这里强化 message 规范 与 在 GitHub 读历史。

学习目标

  • 写清晰、可检索的 commit message(Conventional Commits 入门)
  • 用 git log 与 GitHub Commits 页读历史、看 diff
  • 理解 amend、revert 在协作中的注意事项

工作区 → 暂存 → 提交

git status
git add src/utils.ts README.md
git commit -m "feat(utils): 添加日期格式化 helper"
git push origin main

小步提交: 一个 commit 只做一件事,便于 review 和 git bisect 排错。

Commit message 规范

推荐 Conventional Commits 简化版:

<type>(<scope>): <subject>

<body 可选>

<footer 可选,如 Closes #123>

常见 type:

type含义
feat新功能
fix修复 bug
docs文档
chore构建、依赖、杂项
refactor重构(不改行为)

示例:

git commit -m "fix(api): 修复分页参数 off-by-one

Closes #42"

避免:update、fix bug、改了一下——Review 与 git log --grep 都无法检索。

查看历史

本地:

git log --oneline --graph -15
git log --follow -- path/to/file.ts
git show abc1234

GitHub 仓库页 Commits → 点 SHA → 看 Browse files 与该 commit 的 diff。PR 合并后也会留下 merge commit 或 squash 后的单 commit。

amend 与 revert(协作注意)

# 仅改最后一次 commit(未 push 或 force push 前安全)
git commit --amend -m "docs: 修正 typo"

# 撤销某次提交(生成新 commit,安全)
git revert abc1234

已 push 到共享分支的 commit 不要 amend + force push,除非团队明确允许。公开历史以 revert 或新 fix commit 为准。

关联 Issue

在 message 或 PR 描述写 Closes #123、Fixes #456,合并后 GitHub 自动关闭 Issue(见 ghg-issues)。

练习

  • 对练习仓做 3 次 commit,分别用 feat / docs / fix type
  • git log --oneline --graph 与 GitHub Commits 页对照
  • 找一条含 Co-authored-by 或 issue 引用的开源 commit 阅读

小结

好历史 = 小步提交 + 可读 message + 平台可视化。 下一课分支进阶:rebase、squash、cherry-pick 与 detached HEAD。

加载本节练习…
← 上一课仓库管理下一课 →分支与变基