Git from google techtalks by Randal
- 1. Git from Google TechTalks Randal Schwatz Google TechTalks slides * 朱 伎企 覯 ( ) 襷 覿 磯曙殊覃 螳 覦蟆給 . 朱 蠍語伎 豢螳 る 觚襦蠏 豺 . 企 git 譬 覿 讌 給 .
- 2. Disclaimer git 螻 蟷 ( 襴 覦讀螳 伎蟆 Randal 蠏殊襦 伎 激 ) 襦語 る 蟆暑ル るジ ろ 企慨 git 蟯 mailing-list 譯殊 git patch 襯 蠍一 , UI 覲 螻 蟷 GIT 蟆渚 壱螻 GIT 蟆渚 覓
- 3. What is git? file tree 螳伎 覲蟆曙 蟯襴 Git 豕 : 覿 螳覦 ( 襴 貉る 蟲螳 螳覦 ) 襷 讌 蟯襴 ( 襴 貉る 35000 螳 伎 ) 覲旧″ 覲 Merge 覿蠍 Branch 襷り鍵 ( 覿蠍郁 暑る蟆 朱 覓伎瑚 螳覦蟆 ろ蟆 . ) 觜襴 ( > diff, merge ) 蟆螻 ( 襦語 蟆螻 朱 ... ) Git 螻ろ讌 豕 : 蟠螻 蟠 螳 殊
- 4. Why git? 襴 貉る 螳覦 襷れ 譴 BitKeeper 覓企覦 commit ( 覿一 轟 : 覦壱 覦蟆 ) 覓企 螳 : 碁Μ 覲旧 襦貉 螳覦螻 ろ 覲蟆 豺襯 EMAIL 襦 覲企願碓 襷ろ レ 覲 覲 覯襯 譬 螳覦 覯殊 覲蟆曙 覲 merge 螻糾 蠏
- 5. How does git do it? 覲危ク 螻糾 覲 Universal Public Identifier ( SHA-1 40 char 覓語伎 牛 , 襴 螳襴讌 螻 螳豌伎 手 蠏殊 螳レ ) SVK 螳蟆螻 る ( > @245 螳 @992 企 ) SVK 覿壱 VCS( perl 襦 襷 ) れ襦貊 讌 ( HTTP, SSH, GIT ) る レ 覈螳レ 豌 ( 螻糾 , 覈 覲蟆 蠍磯 螳讌螻 ) 澗覿蠍 branching 螻実覲 merge ( レ ) 覦企覲澗覦企 螻牛給覈襯 豢 覦企襴 豺 讌 ( jpeg 螳 企語 る )
- 6. The SHA1 is King <1> 覈 螳豌企 覲 螻 SHA1 螳螻 . る ( object ) 蟲 : Blobs( 殊 伎 ) 碁Μ (Blobs 碁Μ , 伎語 碁Μ ) 碁Μ 豺覲蟆暑朱 覲螳 覲蟆暑讌 朱 , 伎 覲旧讌 螻 覲語 讌 . 覲旧覲碁 螳 覦 (Commit): A Tree 覿覈螳 蟇磯 , 覿覈螳 Tree( 譯朱 企 , 覿覈襯 牛澗覲 merge . ) Why( 貉る 伎 蠍語 )
- 7. The SHA1 is King <2> Tags: る ( 覲危 commit ) 譯殊襯 ( 覲 , > Kernel 2.6.18-194) 覿螳瑚 旧 Tag 襯 螳覃 .
- 8. Objects live in the repo Git る碁ゼ 朱 燕 . る碁 朱朱 豢螳覃 , 讌 . 谿語^讌 る ( > 讌讌 branch, 豢螳讌襷 commit 讌 蟆 , etc ) れ garbage collect . る碁れ 谿語^讌 . 殊ろ pack (git-gc 襯 牛 豌 . packing 伎 るジ螻褐 . レ襯 手朱 豕 螻糾 讌 ) Packs 螻糾 deltas( る ) 襦 .( 狩 覲螳 , 覿 ロ 蟆 覲襷 朱 ) Packs レ螳 覲 ′ .
- 9. Commits rule the repo る 郁屋豌伎豕 head 覦 commit 襷れ企碁 . 蠏限豕 head れ轟朱 "master" 朱 蟆 .( 豌 repo 襷る 蠍磯 豕豐 覿蠍 branch ) るジ 覿蠍 branch 讌 襷れ伎 ( > ' 覯蠏 螻豺 A' 觚豺襦 覿蠍壱伎 覓語襯 一 覦 commits 豕 Head 牛 れ master 襦 覲 merge . ) 蠏 螳ロ 覈 レ る碁れ 覦 commits れ豕 Head 朱覿 蠏狩 . 轟 覦 朱 覿 碁Μ る碁ゼ 豢 襴 殊 蠏狩 . 覿覈 る碁ゼ 豢覃 覦 commit り骸 蠏碁 螳螳 碁Μ襯 蠏狩 .
- 10. Mapping objects to a file tree " 譴 碁Μ " ".git" 襴襯 豕 蟆暑 螳讌螻 . CVS, SVN 螻朱 襴 襴 蟆暑螳 蟾伎碁 蠏谿 蟆 ( > .svn ) れ . ( "grep -r" ク襴 ) .git 襴 蟲 : config - configuration ( .ini ろ ) objects/* - る レ refs/heads/* - 覿蠍磯 branches ( > "master" ) refs/tags/* - tags logs/* - logs refs/remotes/* - るジ企れ 豢 index - the "index cache" ( る ) HEAD - 覿蠍一 襯実螳襯危 ( " 譴限覦覿蠍 " )
- 11. The index (or "cache") blob る碁れ 襴 " れ 覦 commit " 詩 ( 覦 る蟆 index 襯 れ 覦 next commit 朱 覲蟆 襷 ) " 豢螳 adding files " 碁煙れ k蟆 襷 .( 蠏碁覩襦 給煙 讌 覲蟆曙 豢讌 . ) 覦 commit index 襯 れ 覦 る real commit object 襦 襷 . HEAD index 谿 Diff 覦 commit 讌 覲蟆曙 index working dir 谿 Diff 豢螳 add 讌 覲蟆曙 index 覲 merge 譴 豢 conflict 覲企ゼ 觜
- 12. The great renaming controversy Git 覈 企覲蟆 explicit renaming 讌 朱 螳 蠍磯ゼ 蠍磯讌 . 企覲蟆曙 SHA1 觜蟲襯 牛 . Copy-paste-edits 襦蠏 logs 覯豺 ad-hoc similarity rules 蟆豢螳 朱朱 覲企 貉危郁 谿剰鍵 ロ 螳 覈朱 蠏殊 覈 . 願 覲 merge 襯 覦危 . 褐 覈 蠏朱 覦願 . 蟆磯 : 伎 豢蟆 , 伎 企 貉企襯 豢蟆覲企 壱螻 .
- 13. Git speaks and listens レ repo 螳 襷 襦貊 牛 git data 襯 rsync, http, https, git, ssh, local files Git Core 螳 : CVS 襯 import/export SVN import/export Arch 襯 import CVS/SVN import 襯 牛 襦語 豌 history 襯 企 offline 朱 蠏手 襭れ 譟伎 ( > Perforce) 蟇一襯 螻讌 CVS server .
- 15. Git commands 覈 git 覈轟 "git-" 朱 "git-MUMBLE-FOO bar" = "git MUMBLE-FOO bar" 螳朱襦 "git" 襷 /usr/local/bin 豢螳伎 ろ 螳 企 語 internal call 襷 manpages "git-MUMBLE-FOO" 襦 譟伎 . 蠏碁覩襦 覦 狩 . るジ 覦覯朱 git help MUMBLE-FOO 螳
- 16. "The internet is just a series of tubes" 譴 git low-level git operation 覦郁 plumbing 企 . 螻譴 git higher level action 蠍 porcelain 企 . 螻るΜ Blog る git 覦壱 git 覦郁 plumbing 螻 蠍 porcelain 襯 襾語 殊企 磯 瑚讌 伎 git 蠍 porcelain 襯 牛 伎手鍵 るジ 蠍 porcelain 螳 譟伎 : StGit : stacked git guilt tig(curses-based viewer) qgit
- 17. Creating a repo git-init 蟆暑 .git 襷 . Optional: .gitignore ク讌伎 覓伎 讌 "git-add ." 襦 蟆暑襦覿 覈 豢螳 (.git ) 蠏碁覃 "master" 覿蠍 branch 螳 襷れ伎 . 豕 Head "master" 襯 螳襯危り . git-clone REMOTESPEC git レ repo 襯 るジ レ襦覿 覲旧 朱朱 襴襯 襷 . 朱 working copy .git 蠏瑚崖 豺 蟆讌 覈 覿蠍 remote branch れ 豢 tracked . 蟆讌 豕譬 覿蠍 Head Branch 螳 豐蠍 master 覿蠍磯 讌 .
- 18. Think globally, work locally 朱朱 蟆郁骸覓殊 豢螳 覦 commits れ企 . 覦 commits れ覿蠍 branch 伎 . 覿蠍 branch 企讌伎 覦 commit 企 . 螳 覦 commit 蟆 覃 伎 覿蠍一 豕 head 覿覈 parent 螳 . 覦 覿覈螳 る 覩 覿蠍一 豕 branch head 覦 new commit 螳襯危り . 覿蠍 豕 Branch Head 襭 root 襦 DAG( Directed acyclic graph ) 襯 襷 企 . 覲 merge れ覿覈 multiple parent 襯 覦 commit 企 .
- 19. Typical work flow ク讌 git-add files ( 覲蟆曙 ) file index 豢螳 "git-add ." 覓伎 ignore 蟆れ 誤蟆れ 豢螳 git-status 豕 Head 螻 碁煙 index , 蟆暑螳 谿伎 diff 襴 git-commit ( 覦 commit 譴觜 ) 襦蠏 log 襯 蠍磯 ろ ク讌蠍磯 豌 " 讌ъ 襦蠏 log " 襯 蠍磯螻 覿蠍 current branch 螳覦 朱慨 讌 伎 螳覦 譬 ク讌
- 20. But which branch? <1> 伎 瑚豌 Git 覿蠍 branch 襯 覿蠍 branch 40 覦危 讌襴 覓語願骸 '' : 觜 讌覦 : 覓伎 讌 . 覿蠍磯ゼ 襷 : git-checkout -b topic-name master 螳覦 , 螳覦 , 螳覦 , 蠏碁Μ螻 topic-name 覦 commit 覿蠍 螳覦 覃 : git-checkout master : master 覿蠍磯 螳 git-merge topic-name : 螳覦襭 覿蠍 覲 git-branch -d topic-name 覿蠍郁 HEAD 襦覿 襷 蟲 " 伎 豢 " 覩
- 21. But which branch? <2> 螳螳 覦 commit 覈 commits 覦 a commit 朱 豢 flatten 螻 苦 : git-merge --squash --no-commit t; git-commit ( > 17 覯 覦 覈 貉るる 覯 覦朱 )
- 22. Working in parallel 螳讌 覈襯 螳覦螳 : る git-checkout -b topic1 master 螳覦 , 螳覦 ; 覦 commit ; 螳覦 , 螳覦 ; 覦 commit git-checkout -b topic2 master 螳覦 , 螳覦 ; 覦 commit ; git-checkout topic1 ; 螳覦 螳覦 ; 覦 commit 伎 れ 企至 豕譬 覦蟆瑚 覲 merge : 覲 ろ襴 parallel history 蠏碁 螳螳 襦 覲 蠍磯 - れ rebase : 谿 ろ襴 serial history 蠍磯 覿蠍 豕 head 朱 郁屋
- 23. The merge <1> git-checkout master git-merge topic1; git-branch -d topic1 企 覲 trivial merge "fast forward" merge 企 蟆曙磯 覲危 覲蟆 , 蠏語 覲覃 git-merge topic2 master 豢螳 覲蟆曙 れ伎 蟆曙 企 蟆曙 豢 conflicts 螳 : 覲蟆曙 蟆轟 . 企 覿蠍郁 襦 るゴ蟆 覲蟆渚
- 24. The merge <2> 螳 豢 願屋螻 讌 : git-add 螳 覲蟆渚蟆 轟 git-add . git-commit ( 覲 豢 企至 願屋讌 蠍一 ) 覲 譴 ( るジ 旧企 ): 覲 undo 詩 git-reset --hard HEAD
- 25. The rebase <1> 轟 覿蠍一 覦れ るジ 覿蠍 branch 襦 蠍企 . SHA1 蟾碁Π : 覦 commit れ 豢覿螳 覦 commit 蠍磯 蠏 覦 れ rewrite 朱 襦 覦 蟆企 . SHA1 る . 螻糾 轟 蟆 レ repo 覦 commits 覦 ( push or published) l 蟆曙 蠍磯 - れ rebase 讌 襷蟆 願 譯朱 襦貉 蠍磯レ企 襴 git-rebase master topic master 襯 誤 topic 覲蟆曙 master 蠍磯 焔 . 豢螳る Blog
- 26. The rebase <2> 蠍磯 - れ rebase 覲 豢 merge conflict 螳レ煙 . れ 蠍磯 覦蠑瑚 蠏 覿蠍一 覲蟆曙 れ 蠍磯覓語 螳レ煙伎 . git-rebase --continue or --abort or --skip 覈轟朱 螻 讌讌 譴讌 蟇企 . git-rebase -i ( 語 interactive ) . ろ 磯ゼ 螳讌 譴 . 蠍磯 - れ rebase 覲 "fast forward" 企 git-checkout master; git-merge topic
- 27. Read the history git-log 覲蟆暑れ 豢ロ伎 git-log -p 覲蟆暑れ 襴觜 revisions 伎 diff 襯 豢 git-log --stat diffstat 燕 覲蟆曙 豢 git-log file1 file2 file3 企 殊企 蟆暑れ 覲蟆曙 覲伎譴 .
- 28. What's the difference? git-diff index 螻糾 working tree 伎 谿 蠍 る蟆れ "git-add" 伎狩 "git-commit -a" 覈襦 觜企 . git-diff head 豕 HEAD 螻 螻糾 working tree 伎 谿 "git-commit -a" 覈襦 觜企 . git-diff --cached HEAD index 伎 谿 "git-commit -a" 覈襦 觜企 . git-diff BRANCH_A : 覿蠍 A 豕 Head 螻 螻糾 谿 git-diff BRANCH_A BRANCH_B : 覿蠍 A,B 豕螳 谿
- 29. Barking up the tree 襷 覈豪れ "tree-ish" 覿襴磯蟆語襦覦 . SHA1 る碁ゼ 螳語 . SHA1 豌願 豌 8~9 襷 譴 朱 襷ろ讌 螻 , 螻 蟆企朱 螳 覈襦 A : HEAD, 覿蠍一企 , 蠏語企 , origin 企 覈襦 A れ 蠍磯 . ^n - " 危 n 覯讌 覿覈 " ( 蠍磯蓋 1) ~n n^1 (~3 ^1^1^1 .) :path - tree 襦覿 る碁ゼ > git-diff HEAD^ HEAD 豕 覦 commit 螻 伎 覦 commit 谿 >git-dff HEAD~3 HEAD : 襷讌襷 覦 覘 ?
- 30. Seeing the changes side by side gitk mytopic origin History 襯 Tk widget 朱 (graphical) 螳 谿伎 GUI 襯 牛 覲伎譴 gitk -all 覈 覲企ゼ 覲伎 gitk from..to from to 覲蟆曙 覲伎 git-show-branch myTopic...origin Tk 螳 蟆螻 螳 qgit 覯 覺覲手 蟠 覦 襴 讌蠍 麹 襷 front-end 螳 譟伎
- 31. Playing well with others <1> git-clone 豢讌 tracking 轟 蟆讌 remote 覿蠍 branch 覲危 覿蠍磯 "origin/master" 手 企讌伎 螻旧蠍 朱 覲語 豕 讌 : git-fetch ( 蟆讌襦覿 origin 覿蠍 螳煙 ) 覲蟆曙 螻糾 upstream 蠍磯 - れ rebase: 覈 蠍磯 base るゴ蟆 覿蠍壱覃 覲旧″伎 . git-checkout master # 轟 覿蠍磯 git-rebase origin/master
- 32. Playing well with others <2> 螻糾 Upstream j鍵 push: git-push 螻糾 j鍵 push 蟠 蟆曙 : git-format-patch origin/master 蠏碁Μ螻 蟆暑 蠍 豺襯 覃朱 覲企碁 .
- 33. Keeping things clean git-gc 谿語^讌 る碁ゼ garbage-collector レ る碁れ 讌 る碁ゼ 覈 螻糾 container れ企 : R epack 伎 : 蠏殊炎骸 螻糾 git-gc --prune 蠏朱螳 る碁ゼ 企 . るジ 蟆螻 郁 讌襷蟆 .
- 34. Resetting git-reset --soft 覈 碁煙 , 螻糾 蟇企襴讌 螻 豕 HEAD 襷 覈襦 git-reset --hard # 螻糾 working dir 襷讌襷 覦 commit 朱 襴磯 . git-reset --hard HEAD~3 螳 豕蠏 覦 commit 豬螻 螻糾 working dir 蠏語 襷豢 覦蠖譴 . 企 覿蠍磯ゼ 覦壱る , git-revert 襯 . git-checkout HEAD 覲糾規 襷讌襷 覦 commit 覲糾規 螳語 .
- 35. Pay no attention to the man behind the curtain 覈 蟆暑螳 .gitignore 襯 讌 . 覓語螳 "!" 企 , 覿 一一 . "/" 襯 誤螻 る basename 朱 誤 basename unix program 企 . [ 襷 ] 伎語 fnmatch(3) 襯 牛 shell 企Г豺 "/" 襦 覃 蟆暑襯 詩 レ repo ル螻 豢 .git/info/exclude 襯 牛 .gitignore 觜訣 企 レ repo 襷 企麹 . 螳 螳 讌襷 , 覲旧 clone 讌 .
- 36. Configuration 襷 覈轟 蟆曙れ configurations 襯 螳讌 . git-config name value name 螳 value name "." 覿 譬 讌 . > git config core. filemode true る 朱 ク讌螳 git-config name 螳 value 覲伎 git-config -l れ螳れ 豕 user.email 螻 user.name 覦 commit れ
- 37. other useful porcelain git-archive : tar/zip 襦 tree 襯 企慨 git-bisect : 覓語 覦螻 蟆伎 覦谿剰鍵 git-cherry-pick : 覲 selective merging git-mv : file/dir 覦襯 碁煙 譟一朱 企 覦蠖 git-push : 螻糾 upstream j鍵 git-revert : 伎 覦 commit 覓危 覦 commit git-blame : 螳 燕蟆語
- 38. For further info "Git (softwware)" 襯 Wikipedia 谿場覲手 [ 襷 ] git homepage http://git.or.cz Git wiki https://git.wiki.kernel.org/index.php/Main_Page mailing list 襷 れ . 螳 覯蠏 襴 , 豺 , 企 螻 螳 git り骸 襷覲伎 Freenode IRC #git 豈