从 Git 社区看 Git @ 群英汇蒋鑫 2012/7/19
从我用商业软件制作 PPT 开始说起... 2
Git 像微博? 传统网络媒体 / SVN 微博 / Git 小而固定的编辑群体 人人都是微媒体 集中式的发布流程 基于信任 ( 加粉 ) 的发布和传播 封站 单点故障 禁言 不影响转发 读者参与欲望低 生活的一部分 full of fun 3
新 一代分布式版本控制系统 服务器 终端 终端 DVCS 终端 4
普通青年 如何使用 Git share repo o o o clone clone o o o o o o
普通青年 如何使用 Git share repo o o o commit o o o o o o commit o o o o o o
普通青年 如何使用 Git share repo o o o 压缩提交 修补提交 o o o o o o X o o o o? o o?
普通青年 如何使用 Git share repo o o o o o o o o o o o o o o
普通青年 如何使用 Git share repo o o o o o o push (Fast-Forward PUSH) o o o o o o o o o o o
普通青年 如何使用 Git share repo o o o o o o o o o o o o push 非快进式 (Non-Fast-Forward) o o o o o
普通青年 如何使用 Git share repo o o o o o o o o o o o o fetch o o o o o o o o
普通青年 如何使用 Git share repo o o o o o o o o o o o o merge o o o o o o o o
普通青年 如何使用 Git share repo o o o o o o o o o o o o o o o push DAG o o o o o o o o o
普通青年 如何使用 Git share repo pull o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o
普通青年 如何使用 Git add clone rm mv commit commit push 是 fastforward? 否 pull push add mergetool 是 否 conflict? 15
使用 Git, 项目规模可以提高 一个数量级! 16
SVN 的小而固定的 编辑群 寻找 一个使用 SVN 的开源项目并不容易了 ;-) Apache Subversion( 根据提交说明统计 ) 1 3902 Karl Fogel 2 3728 Hyrum Kurt Wright 3 3440 C. Michael Pilato 4 2422 Julian Foad 5 2354 Bert Huiben... 176 1 Arwin Arni 17
管理负担导致 小而固定编辑群 提交者越多版本库管理越复杂 统 一认证和授权管理 贡献者苦恼 无法版本控制 贡献间接署名 18
Git 的署名作者有多少? 针对 Git v1.7.11 的统计 $ git log --pretty="%an" v1.7.11 \ sort uniq -c sort -rn less -N 1 10904 Junio C Hamano 2 1328 Shawn O. Pearce 3 1103 Linus Torvalds 4 855 Jeff King 5 729 Johannes Schindelin... 1028 1 Aaron Crane 19
Git 中贡献皆署名 $ git log -1 --pretty=fuller v1.7.11~34 commit f50b565a0f3af5a4045d0e713ac43e3f0de3aa9a Author: Jiang Xin <worldhello.net@gmail.com> AuthorDate: Thu May 31 19:20:42 2012 +0800 Commit: Junio C Hamano <gitster@pobox.com> CommitDate: Fri Jun 1 07:43:10 2012-0700 i18n: apply: split to fix a partial i18n message The 4th arg of "new mode (%o) of %s does not match old mode (%o)%s%s" is blank string or string " of ". Even mark the string " of " for a complete i18n, this message is still hard to translate right. Split it into two slight different messages would make l10n teams happy. Signed-off-by: Jiang Xin <worldhello.net@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com> 20
文青 使用 Git 人人皆可 Hack 克隆或更新 未克隆? $ git clone git://git.kernel.org/pub/scm/git/git.git $ cd git 已克隆? $ cd git $ git pull 创建本地分支 myhack $ git checkout -b myhack master Hack... 提交 ( 带 s-o-b 签名 ) $ git commit -s 只读 21
文青 使用 Git 查看 myhack 分支提交 :git show --stat --pretty=fuller HEAD commit e0a47e9dfee5278bad948c91f7707ac766d99d7d Author: Jiang Xin <worldhello.net@gmail.com> AuthorDate: Thu May 31 19:20:42 2012 +0800 Commit: Jiang Xin <worldhello.net@gmail.com> CommitDate: Thu May 31 19:29:28 2012 +0800 时间戳不同? git commit --amend i18n: apply: split to fix a partial i18n message The 4th arg of "new mode (%o) of %s does not match old mode (%o)%s%s" is blank string or string " of ". Even mark the string " of " for a complete i18n, this message is still hard to translate right. Split it into two slight different messages would make l10n teams happy. Signed-off-by: Jiang Xin <worldhello.net@gmail.com> builtin/apply.c 16 ++++++++++++---- 1 个文件被修改, 插入 12 行 (+), 删除 4 行 (-) 22
文青 使用 Git 创建补丁 $ LANGUAGE=C git format-patch --no-thread \ --no-cover-letter HEAD^..HEAD 0001-i18n-apply-split-to-fix-a-partial-i18n-message.patch 查看补丁 $ head -6 0001-i18n-apply-split-*.patch From e0a47e9dfee5278bad948c91f7707ac766d99d7d Mon Sep 17 00:00:00 2001 From: Jiang Xin <worldhello.net@gmail.com> Date: Thu, 31 May 2012 19:20:42 +0800 Subject: [PATCH] i18n: apply: split to fix a partial i18n message The 4th arg of "new mode (%o) of %s does not match old mode (%o)%s%s" 23
文青 使用 Git 通过邮件发送补丁 $ git send-email \ --to "Junio C Hamano <gitster@pobox.com>" \ --cc "Git List <git@vger.kernel.org>" \ --cc "Ævar Arnfjörð Bjarmason <avarab@gmail.com>" \ --cc "Nguyễn Thái Ngọc Duy <pclouds@gmail.com>" \ --cc "Jonathan Nieder <jrnieder@gmail.com>" \ 0001-i18n-apply-split-to-fix-a-partial-i18n-message.patch 邮件相关设置 $ git config -l grep sendemail sendemail.chainreplyto=true sendemail.smtpencryption=ssl sendemail.smtpserver=smtp.googlemail.com sendemail.smtpuser=worldhello.net@gmail.com 24
文青 使用 Git 通过邮件列表评审 25
文青 使用 Git Junio 应用贡献者的补丁 : git am -s file... 官方库中的提交 : git log -1--pretty=fuller HEAD commit f50b565a0f3af5a4045d0e713ac43e3f0de3aa9a Author: Jiang Xin <worldhello.net@gmail.com> AuthorDate: Thu May 31 19:20:42 2012 +0800 Commit: Junio C Hamano <gitster@pobox.com> CommitDate: Fri Jun 1 07:43:10 2012-0700 i18n: apply: split to fix a partial i18n message The 4th arg of "new mode (%o) of %s does not match old mode (%o)%s%s" is blank string or string " of ". Even mark the string " of " for a complete i18n, this message is still hard to translate right. Split it into two slight different messages would make l10n teams happy. Signed-off-by: Jiang Xin <worldhello.net@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com 26
文青 使用 Git 获取上游提交 $ git checkout master $ git pull 删除 myhack 分支 $ git branch -D myhack 上述操作的细节, 参见 Git 代码树中文件 : Documentation/SubmittingPatches 27
文青 使用 Git clone commit commit format-patch send-email clone am add push mergetool 是 否 conflict? 28
疑问 Git 作者有 1000+, 如果只有上述 一种工作流... 是不是提交者将只会有两个? Linus Torvalds Junio C Hamano 29
Git 提交者 针对 Git v1.7.11 统计提交者数量 $ git log --pretty="%cn" v1.7.11 \ sort uniq -c sort -rn less -N 1 24607 Junio C Hamano 2 1454 Shawn O. Pearce 3 1041 Linus Torvalds 4 522 Paul Mackerras 5 372 Eric Wong... 13 63 Jiang Xin... 42 1 Chris Wright 30
Git 提交路径 git-am <patch> integration managers Subtree M. [ 独立项目 : git-gui] Pat Thoyts... Subtree M. [ 独立项目 : gitk] Paul Mackerras... Junio [git] Subtree M. [ 并入项目 : gitweb] Kay Sievers... Subtree M. [ 并入项目 : subtree] Avery Pennarun... Pull [git-po] Jiang Xin... 其他参考 [1] [1] http://git-blame.blogspot.jp/p/note-from-maintainer.html [ 梯子自备 ] 31
子项目的合并 Git 合并的子项目 gitk git-gui gitweb( 不再独立更新 ) git-subtree( 不再独立更新 ) 项目目录结构重叠, 要作为子树合并 git subtree add -P subdir alien-branch git merge -Xsubtree=subdir alien-branch 32
逐级的 Pull request 和 pull clone remote add XX URL commit commit push [-u XX master] fetch origin merge rebase request-pull remote add XX URL merge --abort 是 fetch XX push 否 conflict? merge [--ff-only] XX/master 33
Pull requests 34
Git 本地化工作流 工作流原则 没人了解所有自然语言 : 每个语种 一个负责人 有人要分担 Junio 工作 : 一个 l10n 协调者 本地化贡献者无需精通 Git: 不需要补丁模式 无需自建 Git 服务器 无需命令行操作创建给 l10n 协调者 的 Pull Request GitHub 35
GitHub 简化了如下的流程 fork clone remote add XX URL commit commit push [-u XX master] fetch origin merge --abort merge rebase pull request request-pull merge remote add XX URL 是 fetch XX push 否 conflict? merge --no-ff XX/master 36
git-l10n/git-po 37
本地化中的 Git 操作 zh_cn l10n team: commit & push $ git clone git@github.com:gotgit/git-po_zh-cn.git $ cd git-po_zh-cn; vi po/zh_cn.po $ git commit -s $ git push zh_cn l10n team: GitHub Pull Request l10n coordinator: Pull $ git clone ssh://git@github.com/git-l10n/git-po.git $ cd git-po $ git remote add zh-cn \ git://github.com/gotgit/git-po_zh-cn.git $ git fetch zh-cn $ git merge zh-cn/master l10n coordinator: check, push & pull request $ po-helper.sh check $ git push $ git request-pull... 38
GitHub Pull Request 39
L10n 协调者对 Pull Request 的审核 不能改动 po/ 目录之外的文件 XX.po 文件的语法检查 提交说明格式 : 遵循 50/72 原则 s-o-b 提交说明字符集 : 可用 UTF-8, 但第 一行要全英文 占位式提交用分支暂存 :WIP/XX/master 辅助工具 :po-helper.sh https://github.com/git-l10n/git-po/blob/po-helper/po/po-helper.sh 40
创建给 Junio 的 Pull Request 命令 $ git request-pull junio/master git://github.com/git-l10n/git-po master 输出 Pull Request 文本 The following changes since commit 726016725d45894c061e8d187385327f82803c9f: Sync with i18n-po updates in maint (2012-07-02 15:37:54-0700) are available in the git repository at: git://github.com/git-l10n/git-po for you to fetch changes up to 6792b93b1965561e85be3733bb3ab00b2e598119: l10n: zh_cn.po: translate 29 new messages (2012-07-06 09:11:15 +0800)... 41
Pull Request 发送至 Git 列表 42
Git 工作流汇总 集中式 (Beginner & Business) 未见有开源社区使用此模式 补丁式 :format-patch, mailing list & am 绝大多数 Git 贡献者 通过邮件列表, 全员参与的代码审核 子树合并 git-gui, gitk,... 逐级的 Pull request & pull 例如 Junio 和 integration managers 之间 GitHub Pull Request L10n coordinator 和 l10n team leaders 之间 Linus 不喜欢 GitHub Pull Request https://github.com/torvalds/linux/pull/17#issuecomment-5654674 43
Git 分支管理 四个整合分支 git.git 的四个整合分支 maint : 当前最新发布版本 / 维护版本 最新提交 一定对应 一个 Tag:v1.7.11, v1.7.11.1, v1.7.11.2 master : 下 一个发布版本 git describe 结果 : next pu v1.7.11.2-194-g7bdb7 v1.7.12-rc0 : 主题分支并入 master 分之前的测试 : proposed updates 参考 $ git help workflows 44
Git 分支管理 Merge 的学问 基于最老的支持版本做 Bugfix 合并方向 : maint-1.6.x maint master 维护版本发布 git tag -s v1.7.11.2 maint git log master..maint git checkout master git merge maint git push 新版本发布 git push --tags git tag -s v1.7.12 master git checkout maint git merge --ff-only master git push git push --tags 45
快进式合并 git merge [-ff] myhack other myhack other 46
非快进式合并 git merge --no-ff myhack other myhack other 137 47
仅快进式合并 git merge --ff-only myhack other myhack other 137 48
关于 SVN 和 Git 的 一些思考 SVN 工作区有 一个或多个.svn 目录, 作用? Git 的.git 目录呢? SVN 和 Git 的工作区, 谁的磁盘空间占用大? Git 提交是 Delta 还是全量提交? SVN 本地工作区测试通过, 提交后 CI 服务器测试是否 一定通过? 一个 SVN 版本库最多支持多少提交账号? SVN 和 Git 合并追踪有何不同? 49
企业应用 Git 的担心? 脱库 : 谁不能? 路径授权 拆分版本库授权比 SVN 授权更安全 操作复杂? 亦可集中式 且可实现强制审核 没有大公司在用? Google 50
企业应用 Git 的好处 不存在混合提交, 有 git bisect 更好的分支管理 分布式工作流, 代码评审 对跨地域团队提供天然支持 安全, 管理成本低 快 51
参考 Keynote 下载 : git clone git://github.com/jiangxin/keynote-csdn-tup-24.git https://github.com/jiangxin/keynote-csdn-tup-24/downloads 我的书 http://www.worldhello.net/gotgit/ http://www.worldhello.net/gotgithub/ 微博和微群 http://weibo.com/gotgit http://q.weibo.com/567527 52