• 1. 敏捷吧,Git吧
  • 2. 导言在过去的5,6年里各大开发团队(包括知名的开源项目和一些著名的IT公司)在他们的团队合作模式上发生了重大改变,主要体现在版本控制工具的使用上。 Git改变了/创造了许多开发模式。 介绍Git的一些核心概念和如何在咱们的团队里使用Git,以提高我们的敏捷性和沟通效率。2
  • 3. History2005年由Linus Torvalds创建,用于管理Linux Kernel代码
  • 4. 哪些公司在用4
  • 5. 啥事Git?5
  • 6. Git is aDistributedVersion Control System
  • 7. 或者7
  • 8. Git is a目录管理系统CMS8
  • 9. Git is a历史管理系统Tree9
  • 10. 总之。。。Git 很好!10
  • 11. Distributed一切都在离线下发生每个人都拥有整个历史没有中央集权不需要服务器就可共享变化11
  • 12. Centralized vs. DistributedCentral ServerRemote Server查日志、做比较、在火车/飞机上工作,可随时随地commit12
  • 13. Git对数据的思考方式忘记Centralized VC吧 (…CVS, SVN, TFS...) Git存储数据和对信息的思考方式与其他VCS是完全不同的13
  • 14. 对每个文件记录一个变化列表14
  • 15. 是snapshots,不是difference存储快照的Hash值,SHA-1, 24b9da6552252987aa493b52f8696cd6d3b00373
  • 16. 文件的三种状态存储一个项目的所有元数据和数据解压并放到本地磁盘修改拍快照将快照永久存储
  • 17. 创建一个Git repo$ git init $ git add *.c $ git add README $ git commit -m 'initial project version‘ $ git clone git://github.com/barcoyou/rl.git
  • 18. 文件状态变化untracked vs. trackedTracked: 所有在上一个快照里的文件
  • 19. Untrack -> Staged$ git status On branch master nothing to commit, working directory clean $ vim README $ git status On branch master Untracked files: (use "git add ..." to include in what will be committed) README nothing added to commit but untracked files present (use "git add" to track)
  • 20. Untrack -> Staged$ git add README $ git status On branch master Changes to be committed: (use "git reset HEAD ..." to unstage) new file: README
  • 21. Tracked -> untracked$ vim MPReader.c $ git status On branch master Changes to be committed: (use "git reset HEAD ..." to unstage) new file: README Changes not staged for commit: (use "git add ..." to update what will be committed) (use "git checkout -- ..." to discard changes in working directory) modified: MPReader.c
  • 22. Untracked -> staged$ git add MPReader.c $ git status On branch master Changes to be committed: (use "git reset HEAD ..." to unstage) new file: README modified: MPReader.c
  • 23. 部分staged$ vim MPReader.c $ git status On branch master Changes to be committed: (use "git reset HEAD ..." to unstage) new file: README modified: MPReader.c Changes not staged for commit: (use "git add ..." to update what will be committed) (use "git checkout -- ..." to discard changes in working directory) modified: MPReader.c
  • 24. Staged -> commited$ git add MPReader.c $ git commit -m "Story 182: Fix benchmarks for speed“ Or $ vim MPReader.c $ git commit –a -m "Story 182: Fix benchmarks for speed“ [master 463dc4f] Fix benchmarks for speed 2 files changed, 3 insertions(+) create mode 100644 README
  • 25. Git对commit数据的描述$ git add README test.c LICENSE $ git commit -m 'initial commit of my project'
  • 26. Git对commit数据的描述26
  • 27. Branching一个轻量级的可移动指针,指向某个commit
  • 28. BranchingGit branch是在图节点上的标签 “Sticky Note”
  • 29. Branching当switch branch时,你是在移动 “Sticky Note”29
  • 30. Branching$ git branch testing30
  • 31. 当前branchHEAD在哪,工作目录的内容就是所指向的snapshot
  • 32. 当前branch$ git checkout testing
  • 33. 分支移动$ vim test.c $ git commit -a -m 'made a change'$ git checkout master$ vim test.c $ git commit -a -m 'made other changes'
  • 34. Fast forward merging$ git checkout master $ git merge hotfix
  • 35. Basic merge$ git checkout master $ git merge iss53Git自动确定最好的祖先,而SVN等需要人工介入
  • 36. Merge 冲突$ git merge iss53 Auto-merging index.html CONFLICT (content): Merge conflict in index.html Automatic merge failed; fix conflicts and then commit the result.$ git status On branch master You have unmerged paths. (fix conflicts and run "git commit") Unmerged paths: (use "git add ..." to mark resolution) both modified: index.html no changes added to commit (use "git add" and/or "git commit -a") <<<<<<< HEAD ======= >>>>>>> iss53
  • 37. InitializationC:\> mkdir MPRProject C:\> cd MPRProject C:\MPRProject > git init Initialized empty Git repository in C:/MPRProject/.git C:\MPRProject > notepad README.txt C:\MPRProject > git add . C:\MPRProject > git commit -m 'my first commit' [master (root-commit) 7106a52] my first commit 1 file changed, 1 insertion(+) create mode 100644 README.txt
  • 38. Branches IllustratedmasterA> git commit –m ‘my first commit’38
  • 39. Branches Illustratedmaster> git commit (x2)ABC39
  • 40. Branches Illustratedbug123master> git checkout –b bug123ABC40
  • 41. Branches Illustratedmaster> git commit (x2)ABCDEbug12341
  • 42. Branches Illustratedmaster> git checkout masterABCDEbug12342
  • 43. Branches Illustratedbug123master> git merge bug123ABCDE43
  • 44. Branches Illustratedmaster> git branch -d bug123ABCDE44
  • 45. 复杂点的情况masterABCDEFGbug45645
  • 46. Branches IllustratedmasterABCDEFGbug456> git checkout master46
  • 47. Branches IllustratedmasterABCDEFG> git merge bug456Hbug45647
  • 48. Branches IllustratedmasterABCDEFG> git branch -d bug456H48
  • 49. RebasemasterABCDEFGbug45649
  • 50. RebasemasterABCDE> git rebase masterF’G’bug456FGFG50
  • 51. Fast ForwardmasterABCDE> git checkout master > git merge bug456 F’G’bug45651
  • 52. Branching Review容易并快速创建‘Feature’ Branches本地branch非常强健Rebase一点都不恐怖52
  • 53. 开发是团队运动
  • 54. Sharing commitsL先生的RepoX先生的 RepoK先生的 RepoY先生的RepoABCABCABCABC54
  • 55. 加一个远程Repo55
  • 56. Sharing commits自己本地的RepoX先生的 RepoK先生的RepoY先生的RepoABCABCABCABCRemote RepoABCDDDDD56
  • 57. 配置一个Remote repo两种方式在本地配置一个Repo57
  • 58. Setting up a Remote给以存在的repo加一个remoteC:\MPRProject > git remote add origin https://git01.mpreader.com/mprproject C:\MPRProject > git remote -v origin https://git01.mpreader.com/mprproject (fetch) origin https://git01.mpreader.com/mprproject (push)58
  • 59. Setting up a RemoteClone操作将自动setup the remoteC:\> git clone https://git01.mpreader.com/mprproject Cloning into ‘mprproject'... remote: Counting objects: 3, done. remote: Total 3 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (3/3), done. C:\> cd .\mprproject C:\MPRProject> git remote -v origin https://git01.mpreader.com/mprproject (fetch) origin https://git01.mpreader.com/mprproject (push)59
  • 60. Setting up a Remote给remote一个好记的名字Origin是预留的默认名60
  • 61. Branches Illustrated for remoteAmasterBCDEbug12361
  • 62. Amasterorigin/masterBCDEbug123Branches Illustrated for remote62
  • 63. ABCDEmasterbug123origin/masterBranches Illustrated for remote仅本地知道63
  • 64. ABCDEmasterbug123FGorigin/masterorigin/masterBranches Illustrated for remote64
  • 65. ABCDEmasterbug123> git checkout masterorigin/masterBranches Illustrated for remote65
  • 66. ABCDEmasterbug123FG> git pull originorigin/masterBranches Illustrated for remote66
  • 67. Pull = Fetch + MergeFetch – 更新远程branch的本地版本 把更新的版本与原本地的版本做一次自动merge67
  • 68. ABCDEmasterbug123FGorigin/masterBranches Illustrated for remote68
  • 69. Branches IllustratedABCDEmasterbug123FG> git checkout bug123origin/master69
  • 70. AB’C’D’E’masterbug123FG> git rebase masterorigin/masterBranches Illustrated for remote70
  • 71. AB’C’D’E’masterbug123FG> git checkout masterorigin/masterBranches Illustrated for remote71
  • 72. Amasterbug123FG> git merge bug123B’C’D’E’origin/masterBranches Illustrated for remote72
  • 73. Branches IllustratedAmasterFG> git push originB’C’D’E’bug123origin/master73
  • 74. Push 把你做的更新同步到remote 如果remote已经有了其他更新,push将被拒绝 所以, Push之前先Pull74
  • 75. AmasterFGB’C’D’E’bug123origin/masterBranches Illustrated for remote75
  • 76. Branches IllustratedAmasterFG> git branch -d bug123B’C’D’E’origin/master76
  • 77. Remote Review 加remote是方便我们共享 从remote pull是帮助我们保持最新状态 为保持同步,最好每天做至少一次pull77
  • 78. 短命vs. 长命 Branches本地分支是短命的 保持在非Master分支上做事,使得merge简单 同时在多个feature上工作CreateCommitMergeDelete78
  • 79. 短命 vs. 长命 Branches对多版本发布非常有益 保持Mater和多个story分支 频繁集成 把更新推回remote79
  • 80. 正儿八经的开发了Emasterorigin/master
  • 81. Emasterorigin/masterdevelop> git branch develop正儿八经的开发了81
  • 82. Emasterorigin/masterdevelop> git push origin developorigin/develop正儿八经的开发了82
  • 83. Emasterorigin/masterdevelop> git checkout developorigin/develop正儿八经的开发了83
  • 84. Emasterorigin/masterFGdeveloporigin/develop别人动作还快些84
  • 85. 每天至少拉一次Emasterorigin/masterFGdeveloporigin/develop> git pull origin develop85
  • 86. 有了新的想法Emasterorigin/masterFGdeveloporigin/develop> git checkout –b ideaidea86
  • 87. 我的动作也快Emasterorigin/masterFGdeveloporigin/develop> git commitideaH87
  • 88. 他娘的,谁在主线上改了一个bugEorigin/masterFGorigin/developideaHImasterdevelop88
  • 89. 拉拉更健康Eorigin/masterFGorigin/developideaHmasterdevelop> git pullI89
  • 90. 是时候把我的idea合并会developEorigin/masterFGorigin/developideaHmaster> git checkout developIdevelop90
  • 91. 做了一次快进Eorigin/masterFGorigin/developideaHmaster> git merge idea (fast forward merge)Idevelop91
  • 92. 再见,理想!Eorigin/masterFGorigin/developHmaster> git branch –d ideaIdevelop92
  • 93. 小伙伴们,看看我干了啥Eorigin/masterFGorigin/developHmaster> git push origin developIdevelop93
  • 94. Merge还是rebase,你怎么看?Eorigin/masterFGorigin/developHmaster> git push origin developIdevelop94
  • 95. Merge会这样Eorigin/masterFGorigin/developHmaster> git checkout masterIdevelop95
  • 96. 劈腿啦!!!!Eorigin/masterFGorigin/developHmaster> git merge developIdevelopJ96
  • 97. 小伙伴们,我真的劈腿啦!Eorigin/masterFGorigin/developHmaster> git push originIdevelopJ97
  • 98. 专一一点吧Eorigin/masterFGorigin/developHmaster> git checkout masterIdevelop98
  • 99. 我好一Eorigin/masterFGorigin/developHmaster> git rebase developI’developI99
  • 100. 小伙伴们,我真的很一!Eorigin/masterFGorigin/developHmaster> git push originI’develop100
  • 101. Rebase FlowEorigin/masterFGorigin/developHmasterI’developEorigin/masterFGorigin/developHmasterIdevelopJMerge Flow101
  • 102. 我们团队如何做Master作为产品发布分支 不在Master上开发 所有的开发发生在Feature分支(共享的/本地的) 自己把握哪些分支是共享的,哪些只在本地102
  • 103. 规范只用于产品发布,稳定的开发、测试新需求、新功能、bugfix103
  • 104. (本页无文本内容)
  • 105. http://Git-SCM.com
  • 106. Tools / ResourcesPro Git (Book) http://www.git-scm.com/book TortoiseGit (with TortoiseMerge) http://code.google.com/p/tortoisegit GitHub for Windows http://windows.github.com/
  • 107. Thanks!