SCM for Android Developers Using Git
-
Upload
tony-hillerson -
Category
Technology
-
view
4.441 -
download
2
description
Transcript of SCM for Android Developers Using Git
![Page 1: SCM for Android Developers Using Git](https://reader030.fdocuments.us/reader030/viewer/2022020115/540691108d7f72d8088b462e/html5/thumbnails/1.jpg)
For the Android DeveloperAnDevCon 2011 : Tony Hillerson#AnDevCon #effectiveuihttp://www.slideshare.net/thillerson/scm-for-android-developers-using-git
Git
![Page 2: SCM for Android Developers Using Git](https://reader030.fdocuments.us/reader030/viewer/2022020115/540691108d7f72d8088b462e/html5/thumbnails/2.jpg)
About Me• Worked with Android and Git for a few years now
• O’Reilly Screencaster: Developing Android Applications
• http://training.oreilly.com/androidapps/
• http://training.oreilly.com/androidapps2/
• Tech Reviewer:
![Page 3: SCM for Android Developers Using Git](https://reader030.fdocuments.us/reader030/viewer/2022020115/540691108d7f72d8088b462e/html5/thumbnails/3.jpg)
PreliminariesGetting Git and Getting Set Up
![Page 4: SCM for Android Developers Using Git](https://reader030.fdocuments.us/reader030/viewer/2022020115/540691108d7f72d8088b462e/html5/thumbnails/4.jpg)
What’s a Git?
A completely ignorant, childish person with no manners.- http://urbandictionary.com
Linus Torvaldshttp://en.wikipedia.org/wiki/Linus_Torvalds
![Page 5: SCM for Android Developers Using Git](https://reader030.fdocuments.us/reader030/viewer/2022020115/540691108d7f72d8088b462e/html5/thumbnails/5.jpg)
What’s a Git?
Git is a free & open source, distributed version control system designed to handle everything from
small to very large projects with speed and efficiency.
- http://git-scm.com
![Page 6: SCM for Android Developers Using Git](https://reader030.fdocuments.us/reader030/viewer/2022020115/540691108d7f72d8088b462e/html5/thumbnails/6.jpg)
Getting Set Up on Mac• Homebrew - http://mxcl.github.com/homebrew/
• MacPorts - http://www.macports.org/
![Page 7: SCM for Android Developers Using Git](https://reader030.fdocuments.us/reader030/viewer/2022020115/540691108d7f72d8088b462e/html5/thumbnails/7.jpg)
Getting Set Up on Windows• msysgit -http://code.google.com/p/msysgit/
• Cygwin - http://www.cygwin.com/
![Page 8: SCM for Android Developers Using Git](https://reader030.fdocuments.us/reader030/viewer/2022020115/540691108d7f72d8088b462e/html5/thumbnails/8.jpg)
Getting Set Up on Linux• apt, etc - you probably know the drill
![Page 9: SCM for Android Developers Using Git](https://reader030.fdocuments.us/reader030/viewer/2022020115/540691108d7f72d8088b462e/html5/thumbnails/9.jpg)
Mac
WIN
Mac
MAC
Gooies!• Git Tower - http://git-tower.com
• Brother Bard’s GitX fork - http://brotherbard.com/blog/2010/03/experimental-gitx-fork/
• Tortoise Git - http://code.google.com/p/tortoisegit/
![Page 10: SCM for Android Developers Using Git](https://reader030.fdocuments.us/reader030/viewer/2022020115/540691108d7f72d8088b462e/html5/thumbnails/10.jpg)
Eclipse Integration• http://www.eclipse.org/egit/
![Page 11: SCM for Android Developers Using Git](https://reader030.fdocuments.us/reader030/viewer/2022020115/540691108d7f72d8088b462e/html5/thumbnails/11.jpg)
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
![Page 12: SCM for Android Developers Using Git](https://reader030.fdocuments.us/reader030/viewer/2022020115/540691108d7f72d8088b462e/html5/thumbnails/12.jpg)
Note• Code may be in backticks: `git <command>`
• Don’t input the backticks
![Page 13: SCM for Android Developers Using Git](https://reader030.fdocuments.us/reader030/viewer/2022020115/540691108d7f72d8088b462e/html5/thumbnails/13.jpg)
The Command LineA Short Sermon
![Page 14: SCM for Android Developers Using Git](https://reader030.fdocuments.us/reader030/viewer/2022020115/540691108d7f72d8088b462e/html5/thumbnails/14.jpg)
Seven Use CasesWhere Git will Make your Life Easier
![Page 15: SCM for Android Developers Using Git](https://reader030.fdocuments.us/reader030/viewer/2022020115/540691108d7f72d8088b462e/html5/thumbnails/15.jpg)
Project HistoryGit will Make your Life Easier
![Page 16: SCM for Android Developers Using Git](https://reader030.fdocuments.us/reader030/viewer/2022020115/540691108d7f72d8088b462e/html5/thumbnails/16.jpg)
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
![Page 17: SCM for Android Developers Using Git](https://reader030.fdocuments.us/reader030/viewer/2022020115/540691108d7f72d8088b462e/html5/thumbnails/17.jpg)
Simple Commands• `git init`- Creates an empty Git repository
• .gitignore - tells git to ignore certain files
• `git add` - Adds a file to the stage (“stages a file”)
• `git rm` - Removes from version control
• `git commit` - Commits the staged changes to the (local)
repository
• `git log`
• `git add -i` Interactive Add
![Page 18: SCM for Android Developers Using Git](https://reader030.fdocuments.us/reader030/viewer/2022020115/540691108d7f72d8088b462e/html5/thumbnails/18.jpg)
or
Simple Workflow
gitinit
changes
gitadd git commit
changes
gitadd git commit
changes
gitadd git commit
... ∞
86650c185eda50c9f9d58e2fbdf8b7113e5dee54
6facfd9f34173f4fb024196996e948a87c85eb56
b02ef5bf190e28ba24eab3ffab6133181cb5b5ef
gitclone
![Page 19: SCM for Android Developers Using Git](https://reader030.fdocuments.us/reader030/viewer/2022020115/540691108d7f72d8088b462e/html5/thumbnails/19.jpg)
.gitignore• Can be nested deeply
• https://github.com/github/gitignore
• Use it! Contribute!
![Page 20: SCM for Android Developers Using Git](https://reader030.fdocuments.us/reader030/viewer/2022020115/540691108d7f72d8088b462e/html5/thumbnails/20.jpg)
Git Log - The Project’s History• What got committed?
• Commit messages
• Content
• When? Who?
![Page 21: SCM for Android Developers Using Git](https://reader030.fdocuments.us/reader030/viewer/2022020115/540691108d7f72d8088b462e/html5/thumbnails/21.jpg)
What’s With all the Characters?
“... 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)
86650c185eda50c9f9d58e2fbdf8b7113e5dee54• SHA1 Hash
• Uniquely identifies a commit
• Secure - very unlikely that someone can tamper with content in a repository
![Page 22: SCM for Android Developers Using Git](https://reader030.fdocuments.us/reader030/viewer/2022020115/540691108d7f72d8088b462e/html5/thumbnails/22.jpg)
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 add changes
• Individual commits shouldn’t leave things broken
• Try to commit some useful feature or bug fix all together
![Page 23: SCM for Android Developers Using Git](https://reader030.fdocuments.us/reader030/viewer/2022020115/540691108d7f72d8088b462e/html5/thumbnails/23.jpg)
Getting Out of TroubleGit will Make your Life Easier
![Page 24: SCM for Android Developers Using Git](https://reader030.fdocuments.us/reader030/viewer/2022020115/540691108d7f72d8088b462e/html5/thumbnails/24.jpg)
Advanced Commands• blame
• checkout
• commit -a
• reset
• stash
• commit --amend
• revert
![Page 25: SCM for Android Developers Using Git](https://reader030.fdocuments.us/reader030/viewer/2022020115/540691108d7f72d8088b462e/html5/thumbnails/25.jpg)
git blame
• remember: git help blame
• Who broke the build??? etc...
![Page 26: SCM for Android Developers Using Git](https://reader030.fdocuments.us/reader030/viewer/2022020115/540691108d7f72d8088b462e/html5/thumbnails/26.jpg)
git checkout, commit -a, reset
• remember: git help reset
• `git commit -a` = commit bypassing `git add`
• `git checkout <filename>` = remove all unstaged changes
• `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.) = rollback commits
to working tree
• `git reset --soft` = rollback commit to stage
![Page 27: SCM for Android Developers Using Git](https://reader030.fdocuments.us/reader030/viewer/2022020115/540691108d7f72d8088b462e/html5/thumbnails/27.jpg)
git stash
• remember: git help stash
• Stash away changes in a safe place
![Page 28: SCM for Android Developers Using Git](https://reader030.fdocuments.us/reader030/viewer/2022020115/540691108d7f72d8088b462e/html5/thumbnails/28.jpg)
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
![Page 29: SCM for Android Developers Using Git](https://reader030.fdocuments.us/reader030/viewer/2022020115/540691108d7f72d8088b462e/html5/thumbnails/29.jpg)
git revert
• Commits the reverse of a commit
• The previous commit is still there
• != svn revert
![Page 30: SCM for Android Developers Using Git](https://reader030.fdocuments.us/reader030/viewer/2022020115/540691108d7f72d8088b462e/html5/thumbnails/30.jpg)
CollaborationGit will Make your Life Easier
![Page 31: SCM for Android Developers Using Git](https://reader030.fdocuments.us/reader030/viewer/2022020115/540691108d7f72d8088b462e/html5/thumbnails/31.jpg)
Remotes• remote add
• push
• clone
• pull
• fetch
![Page 32: SCM for Android Developers Using Git](https://reader030.fdocuments.us/reader030/viewer/2022020115/540691108d7f72d8088b462e/html5/thumbnails/32.jpg)
Strategies• Star
• Peer to Peer
• Blessed Repository
• Hierarchical
![Page 33: SCM for Android Developers Using Git](https://reader030.fdocuments.us/reader030/viewer/2022020115/540691108d7f72d8088b462e/html5/thumbnails/33.jpg)
Star
“The Server”Committer
Committer
Committer
Committer
Committer
Committer
![Page 34: SCM for Android Developers Using Git](https://reader030.fdocuments.us/reader030/viewer/2022020115/540691108d7f72d8088b462e/html5/thumbnails/34.jpg)
• ssh://user@computer:path/to/repo.git
• http
• Gitosis
• Gitolite
Peer to N Peers
Peer Peer
Peer
![Page 35: SCM for Android Developers Using Git](https://reader030.fdocuments.us/reader030/viewer/2022020115/540691108d7f72d8088b462e/html5/thumbnails/35.jpg)
Hierarchical (Linux model)
Developer Developer
Lieutenant
Developer Developer
Lieutenant
Dictator ... etc. Maintains a “blessed repository”
![Page 36: SCM for Android Developers Using Git](https://reader030.fdocuments.us/reader030/viewer/2022020115/540691108d7f72d8088b462e/html5/thumbnails/36.jpg)
Topical DevelopmentGit will Make your Life Easier
![Page 37: SCM for Android Developers Using Git](https://reader030.fdocuments.us/reader030/viewer/2022020115/540691108d7f72d8088b462e/html5/thumbnails/37.jpg)
Branching• checkout -b
• merging
• Rebasing
• cherry-pick
![Page 38: SCM for Android Developers Using Git](https://reader030.fdocuments.us/reader030/viewer/2022020115/540691108d7f72d8088b462e/html5/thumbnails/38.jpg)
How To Think About Branching• Topic Branches
• Mainline
• What do you want “master” to mean?
• Branching examples
![Page 39: SCM for Android Developers Using Git](https://reader030.fdocuments.us/reader030/viewer/2022020115/540691108d7f72d8088b462e/html5/thumbnails/39.jpg)
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
![Page 40: SCM for Android Developers Using Git](https://reader030.fdocuments.us/reader030/viewer/2022020115/540691108d7f72d8088b462e/html5/thumbnails/40.jpg)
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
![Page 41: SCM for Android Developers Using Git](https://reader030.fdocuments.us/reader030/viewer/2022020115/540691108d7f72d8088b462e/html5/thumbnails/41.jpg)
Mac
add_login_activity
Mac
master
Branching
fb4f5d9 c5083fa
9aa8827 fe594ce ccb6f5e
git checkout -b add_login_activity
![Page 42: SCM for Android Developers Using Git](https://reader030.fdocuments.us/reader030/viewer/2022020115/540691108d7f72d8088b462e/html5/thumbnails/42.jpg)
Mac
add_login_activity
Mac
master
Branching: Merging
fb4f5d9 c5083fa
9aa8827 fe594ce ccb6f5e
3f43fa3
git checkout master
9aa8827 fe594ce ccb6f5e
git merge add_login_activity
![Page 43: SCM for Android Developers Using Git](https://reader030.fdocuments.us/reader030/viewer/2022020115/540691108d7f72d8088b462e/html5/thumbnails/43.jpg)
Mac
add_login_activity
Mac
master
Branching: Rebasing
fb4f5d9 c5083fa
9aa8827 fe594ce ccb6f5e
3f43fa3
Mac
add_login_activit
Mac
master
fb4f5d9 c5083fa
9aa8827 fe594ce ccb6f5e
3f43fa3
after`git rebase master`
before
![Page 44: SCM for Android Developers Using Git](https://reader030.fdocuments.us/reader030/viewer/2022020115/540691108d7f72d8088b462e/html5/thumbnails/44.jpg)
Branching: Rebasing• Better than merging
• Don’t use if you’ve pushed your branch to a remote
• Git will complain about refs
• Can override with `git push -force`
• Also available on `git pull --rebase`
• Helpful for avoiding merge commits
• May cause problems if git can’t automatically merge
• `git reset HEAD` and start over with normal `git pull`
![Page 45: SCM for Android Developers Using Git](https://reader030.fdocuments.us/reader030/viewer/2022020115/540691108d7f72d8088b462e/html5/thumbnails/45.jpg)
Mac
add_login_activity
Mac
master
Cherry-pick
fb4f5d9 c5083fa
9aa8827 fe594ce ccb6f5e
3f43fa3
git cherry-pick fe594ce
A new commit with the changes
from fe594ce
![Page 46: SCM for Android Developers Using Git](https://reader030.fdocuments.us/reader030/viewer/2022020115/540691108d7f72d8088b462e/html5/thumbnails/46.jpg)
Cherry Picking• Doesn’t add a reference to the old commit
• Only applies the changes
• Future merges should apply cleanly
![Page 47: SCM for Android Developers Using Git](https://reader030.fdocuments.us/reader030/viewer/2022020115/540691108d7f72d8088b462e/html5/thumbnails/47.jpg)
Release ManagementGit will Make your Life Easier
![Page 48: SCM for Android Developers Using Git](https://reader030.fdocuments.us/reader030/viewer/2022020115/540691108d7f72d8088b462e/html5/thumbnails/48.jpg)
Tagging• tag
• push --tags
![Page 49: SCM for Android Developers Using Git](https://reader030.fdocuments.us/reader030/viewer/2022020115/540691108d7f72d8088b462e/html5/thumbnails/49.jpg)
Mac
master
Tagging
fb4f5d9 c5083fa 3f43fa3
git tag -a -m"Tagging v1.0" v1.0 c5083fa
• Both -v1.0 and c5083fa will point to c5083fa
• Push this tag with `git push --tags`
• Can be cryptologically signed
![Page 50: SCM for Android Developers Using Git](https://reader030.fdocuments.us/reader030/viewer/2022020115/540691108d7f72d8088b462e/html5/thumbnails/50.jpg)
Bug FixingGit will Make your Life Easier
![Page 51: SCM for Android Developers Using Git](https://reader030.fdocuments.us/reader030/viewer/2022020115/540691108d7f72d8088b462e/html5/thumbnails/51.jpg)
Bug Fixing• blame
• bisect
![Page 52: SCM for Android Developers Using Git](https://reader030.fdocuments.us/reader030/viewer/2022020115/540691108d7f72d8088b462e/html5/thumbnails/52.jpg)
Bisectgit bisect start
Macfb4f5d9 c5083fa 3f43fa3 9aa8827 fe594ce ccb6f5e 2e531cb
git bisect bad
Macfb4f5d9 c5083fa 3f43fa3 9aa8827 fe594ce ccb6f5e 2e531cb
git bisect good fb4f5d9
Macfb4f5d9 c5083fa 3f43fa3 9aa8827 fe594ce ccb6f5e 2e531cb
git bisect goodgit bisect goodgit bisect bad
Git tells you this was the first bad commit
HEAD
HEAD
HEAD
![Page 53: SCM for Android Developers Using Git](https://reader030.fdocuments.us/reader030/viewer/2022020115/540691108d7f72d8088b462e/html5/thumbnails/53.jpg)
Open Source CodeGit will Make your Life Easier
![Page 54: SCM for Android Developers Using Git](https://reader030.fdocuments.us/reader030/viewer/2022020115/540691108d7f72d8088b462e/html5/thumbnails/54.jpg)
Github.com• Search it!
• Forking
• Pull Requests
![Page 55: SCM for Android Developers Using Git](https://reader030.fdocuments.us/reader030/viewer/2022020115/540691108d7f72d8088b462e/html5/thumbnails/55.jpg)
Thank you!
For the Android DeveloperAnDevCon 2011 : Tony Hillerson
Git