Git For The Android Developer

  • View
    12.070

  • Download
    5

Embed Size (px)

DESCRIPTION

SL

Text of Git For The Android Developer

  • 1.GitFor the Android DeveloperTony Hillerson, AnDevCon Fall 2011#AnDevCon #effectiveui @thillersonhttp://www.slideshare.net/thillerson/git-for-android-developers

2. About Me Worked with Android and Git for a few years now OReilly Screencaster: Developing Android Applications http://training.oreilly.com/androidapps/ http://training.oreilly.com/androidapps2/ Tech Reviewer 3. Conference App Get it, rate stuff 4. Diving Right InLearning by Doing 5. gitgit or cloneinitgit86650c185eda50c9f9d58e2fbdf8b7113e5dee54git commit changesaddgitgit commit 6facfd9f34173f4fb024196996e948a87c85eb56 changesaddgitgit commit b02ef5bf190e28ba24eab3ffab6133181cb5b5ef changesadd... Simple Workflow 6. .gitignore Can be nested deeply https://github.com/github/gitignore 7. Git Log - The Projects History What got committed? Commitmessages Content When? Who? 8. Remotes remote add clone fetch pull push 9. Tagginggit tag -a -m"Tagging v1.0" v1.0 c5083famasterMacfb4f5d9c5083fa3f43fa3Both -v1.0 and c5083fa will point to c5083faPush this tag with `git push --tags`Can be cryptologically signed 10. Recap of Simple Commands git init - Creates an empty Git repository git add -Adds a file to the stage (stages a file) git rm - Removesfrom version control git commit - Commits the staged changes to the (local)repository git log -A view of the history git tag -Names a commit .gitignore- tells git to ignore certain files 11. Why Source Control? For the solo developer? Protection against mistakes Freedom ... to refactor ... to experiment For the development team? All of the above, plus: Parallel development Merging different code branches 12. PreliminariesGetting Git and Getting Set Up 13. Whats a Git?A completely ignorant, childish person with no manners.- http://urbandictionary.comLinus Torvaldshttp://en.wikipedia.org/wiki/Linus_Torvalds 14. Whats a Git? Git is a free & open source, distributed versioncontrol system designed to handle everything from small to very large projects with speed andefficiency. - http://git-scm.com 15. Getting Set Up on Mac Homebrew- http://mxcl.github.com/homebrew/ MacPorts - http://www.macports.org/ 16. Getting Set Up on Windows msysgit -http://code.google.com/p/msysgit/ 17. Getting Set Up on Linux apt, etc - you probably know the drill 18. Gooies! Git Tower - http://git-tower.comM BrotherMacBards GitX fork -Ahttp://brotherbard.com/blog/2010/03/experimental-gitx-fork/ C TortoiseGit - http://code.google.com/p/tortoisegit/ WMacIN 19. Eclipse Integration http://www.eclipse.org/egit/ 20. Reference Git - http://git-scm.com/ ProGit - http://progit.org/book/ - Scott Chacon Insider Guide to Github - http://www.pragprog.com/screencasts/v-scgithub/ insider-guide-to-github - Scott Chacon 21. The Command LineA Short Sermon 22. The Guts of GitThe Little Bits that Make Git Different 23. Whats With all the Characters?86650c185eda50c9f9d58e2fbdf8b7113e5dee54 SHA1 Hash Uniquely identifies a commit Secure - very unlikely that someone can tamper with content in a repository ... to have a probability of a SHA1-hash collision rise to 1/2, you need about 10^24 objects ...- Scott Chacon in Pro Git (paraphrased) 24. In Git There Are Only... Blobs Trees Commits 25. Blobs The contents of your files are stored as binary filesin .git/objects Git is efficient. It only stores the same content once. Identified by a SHA-1 Show blob contents with e.g. git show c7fb9f5 26. Trees Trees give structure to blobs Trees are also stored in .git/objects Identified by SHA-1 Viewa tree with ls-tree, e.g. `git ls-tree HEAD` 27. Commits Identified by a SHA-1 Points to one tree Has a required message May have one (or more) parent commit(s) Show the reachable commits from a commit: git rev-listHEAD 28. Refs Point to commits .git/refs/heads - the latest commits in local branches HEAD- the latest commit on the current branch 29. Blobs Are Content b84ed8ede8d5cf6579a3b1 30. Trees Give Structure9899d2c b84ed8ed foo.txt 579a3b1bar.txt e8d5cf6baz.html trees can point3ffb35b /images to other trees 31. Commits Point to Treesd414c3e9899d2c Updated the main activityb84ed8ed foo.txt 579a3b1 bar.txt e8d5cf6 baz.html 3ffb35b /images 32. Commits have Parents d414c3e Updated the main activity 090c953Fixed bug #42 4493671 Added RoboGuice c1d1f60Initial commit 33. Refs Point to Commits HEAD d414c3eUpdated the main activity090c953 Fixed bug #424493671Added RoboGuicec1d1f60 Initial commit 34. And Thats All YouNeed To Know AboutGit 35. And Thats All YouNeed To Know AboutGit (Mostly) 36. Sweet Moves with GitSweet, Sweet Moves 37. Interactive AddBuilding Semantic Commits 38. Interactive Add - Building Commits `git add` simply adds to the stage `git commit -a` will commit all changes to tracked files(add and commit) `git add -i` -- a command line tool to interactively addchanges Individual commits shouldnt leave things broken Try to commit some useful feature or bug fix all together 39. Amending A CommitFix the Last Commit 40. git commit --amend Oops! I misspelled something in the commit message Oops! I did `git commit -a` and forgot to `git add` a file Oops! I just committed a bug USE ONLY BEFORE YOU SHARE CHANGES 41. Git RevertMore Like Git Reverse 42. git revert Commitsthe reverse of a commit The previous commit is still there != svn revert 43. Git StashLike a Little Repo In Your Repo 44. git stash remember:git help stash Stash away changes in a safe place 45. BranchingHitting Save Before You Fight the Level Boss 46. Branching checkout -b merging rebasing 47. How To Think About Branching Topic Branches Mainline Whatdo you want master to mean? Branching examples 48. Topic Branches Branching is about controlling feature sets Make a new branch for a story Make a new branch for a bug fix Make a new branch to spike something 49. Team Branching Strategies What do you want master to mean? Keep master deployable? one strategy for web software Use master as an integration branch? Each developer uses topic branches and integrates to master Make a branch for releases 50. Branchinggit checkout -b add_login_activitymasterMacfb4f5d9c5083fa add_login_activity Mac 9aa8827fe594ce ccb6f5e 51. Branching: Merginggit checkout mastergit merge add_login_activitymasterMac 9aa8827 fe594ceccb6f5efb4f5d9 c5083fa 3f43fa3add_login_activityMac9aa8827 fe594ce ccb6f5e 52. Branching: Rebasing master Mac fb4f5d9c5083fa 3f43fa3add_login_activitybeforeMac9aa8827fe594ce ccb6f5emasterMac fb4f5d9 c5083fa3f43fa3 add_login_activityafterMac 9aa8827fe594ce ccb6f5e`git rebase master` 53. Branching: Rebasing Better than merging Dont use if youve pushed your branch to a remote Can override with `git push -force` 54. Git Pull --rebase Also available: `git pull --rebase` Helpful for avoiding merge commits Maycause problems if git cant automatically merge `git reset HEAD` and start over with normal `git pull` 55. Cherry PickIll Take One Of Those... And One Of Those... 56. Cherry-pick git cherry-pick fe594ceA new commit withmaster the changes fromfe594ceMacfb4f5d9 c5083fa 3f43fa3add_login_activityMac9aa8827 fe594ceccb6f5e 57. Interactive RebaseRewrite History 58. Interactive Rebase - Fixing History git rebase -i [commit]A list of all commits in the current order Reorder Fix a certain commit Squashcommits together Delete commits DONT USE AFTER YOUVE PUSHED 59. Whoops!Lots Of Ways To Fix It 60. git checkout `git checkout [filename]` = remove all unstaged changes 61. git reset `git reset [filename]` = opposite of `git add [filename]` `git reset HEAD` = same as above - acts on all changes `git reset HEAD^` (also ^^, or ~1, ~42, etc.) = rollbackcommits to working tree All examplesof mixed reset 62. git reset soft git reset --soft [commit] Moves HEAD to commit Puts the popped contents on the index 63. git reset mixed (default) git reset [commit] Moves HEAD to commit Puts the popped contents on the index Moves the index to the working tree as changes 64. git reset hard git reset --hard [commit] Moves HEAD to commit Puts the popped contents on the index Moves the index to the working tree as changes Makesthe working tree look like the index DESTRUCTIVE 65. git reset use cases Backthat last commit up (git reset HEAD^) Dont forget `commit --amend` Oops,didnt mean to commit that fileI meant that commit to be on a branch! 66. The Take Home SCMIs Important No matter what kind of developer you are Git is fundamentally different from the others Its not a database of patches Its a history of filesystem snapshots It gives you freedom to innovate, make mistakes, andcollaborate. 67. Thank you! #AnDevCon #effectiveui @thillerson http://github.com/thillerson http://slideshare.com/thillersonHalf Off My Git CourseThese SlidesGit For the Android Developer Tony Hillerson AnDevCon Fall 2011