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
For the Android DeveloperAnDevCon 2011 : Tony Hillerson#AnDevCon #effectiveuihttp://www.slideshare.net/thillerson/scm-for-android-developers-using-git
Git
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:
PreliminariesGetting Git and Getting Set Up
What’s a Git?
A completely ignorant, childish person with no manners.- http://urbandictionary.com
Linus Torvaldshttp://en.wikipedia.org/wiki/Linus_Torvalds
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
Getting Set Up on Mac• Homebrew - http://mxcl.github.com/homebrew/
• MacPorts - http://www.macports.org/
Getting Set Up on Windows• msysgit -http://code.google.com/p/msysgit/
• Cygwin - http://www.cygwin.com/
Getting Set Up on Linux• apt, etc - you probably know the drill
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/
Eclipse Integration• http://www.eclipse.org/egit/
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
Note• Code may be in backticks: `git <command>`
• Don’t input the backticks
The Command LineA Short Sermon
Seven Use CasesWhere Git will Make your Life Easier
Project HistoryGit will Make your Life Easier
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
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
or
Simple Workflow
gitinit
changes
gitadd git commit
changes
gitadd git commit
changes
gitadd git commit
... ∞
86650c185eda50c9f9d58e2fbdf8b7113e5dee54
6facfd9f34173f4fb024196996e948a87c85eb56
b02ef5bf190e28ba24eab3ffab6133181cb5b5ef
gitclone
.gitignore• Can be nested deeply
• https://github.com/github/gitignore
• Use it! Contribute!
Git Log - The Project’s History• What got committed?
• Commit messages
• Content
• When? Who?
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
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
Getting Out of TroubleGit will Make your Life Easier
Advanced Commands• blame
• checkout
• commit -a
• reset
• stash
• commit --amend
• revert
git blame
• remember: git help blame
• Who broke the build??? etc...
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
git stash
• remember: git help stash
• Stash away changes in a safe place
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
git revert
• Commits the reverse of a commit
• The previous commit is still there
• != svn revert
CollaborationGit will Make your Life Easier
Remotes• remote add
• push
• clone
• pull
• fetch
Strategies• Star
• Peer to Peer
• Blessed Repository
• Hierarchical
Star
“The Server”Committer
Committer
Committer
Committer
Committer
Committer
• ssh://user@computer:path/to/repo.git
• http
• Gitosis
• Gitolite
Peer to N Peers
Peer Peer
Peer
Hierarchical (Linux model)
Developer Developer
Lieutenant
Developer Developer
Lieutenant
Dictator ... etc. Maintains a “blessed repository”
Topical DevelopmentGit will Make your Life Easier
Branching• checkout -b
• merging
• Rebasing
• cherry-pick
How To Think About Branching• Topic Branches
• Mainline
• What do you want “master” to mean?
• Branching examples
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
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
Mac
add_login_activity
Mac
master
Branching
fb4f5d9 c5083fa
9aa8827 fe594ce ccb6f5e
git checkout -b add_login_activity
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
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
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`
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
Cherry Picking• Doesn’t add a reference to the old commit
• Only applies the changes
• Future merges should apply cleanly
Release ManagementGit will Make your Life Easier
Tagging• tag
• push --tags
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
Bug FixingGit will Make your Life Easier
Bug Fixing• blame
• bisect
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
Open Source CodeGit will Make your Life Easier
Github.com• Search it!
• Forking
• Pull Requests
Thank you!
For the Android DeveloperAnDevCon 2011 : Tony Hillerson
Git