Master the art and practice of DVCS
NICOLA PAOLUCCI • DEVELOPER INSTIGATOR • ATLASSIAN • @DURDN
Power routines of experienced Git users
R E M O V E B I N A R I E S
Follow along, solve real world daily version control situations
C O N F L I C T R E S O L U T I O N
M E R G E S T R AT E G I E S
I N T E R A C T I V E C O M M I T S
A M E N D A N D R E B A S E
A D V E N T U R E AWA I T S
Follow along the adventure
This session won’t be interactive but you can follow along and try to beat me to tasks by
cloning this repository
git clone \ [email protected]:nicolapaolucci/starwars-summary.git
A D V E N T U R E AWA I T S
House keeping [1]Get a nice prompt: Liquid prompt is awesome
http://bit.do/liquid-prompt
A D V E N T U R E AWA I T S
House keeping [2]
If you are creating a new repository, start with an empty commit and tag it
git commit -m"[empty] Initial commit" --allow-empty
git tag initial <first-sha-1> -m"Tag initial commit"
A D V E N T U R E AWA I T S
House keeping [3]
To speed up the typing I have created a few aliases that we will re-use throughout
ls = log --decorate --oneline
ll = log --decorate --numstat
http://bit.do/gitconfig
T H E O RY
Always think of these
Work directory
Which tree does my command affect?
Index or Staging area
Local repository (.git) Remotes
U N D O I N G S
Memorise or alias this to amend quickly
Amend the last commit with everything I have here uncommitted and new
caa = commit -a --amend -C HEAD
T H E O RY
Default git reset is of type mixed…
Work directory
Which tree does my command affect?
Index or Staging area
Local repository (.git)
HEAD
master
git reset HEAD~
HEADHEAD
HEAD
changes
T H E O RY
Default git reset is a mixed reset…
Work directory
Which tree does my command affect?
Index or Staging area
Local repository (.git)
HEADmaster
git reset HEAD~
HEADHEAD
Ancestry referencesYou can specify commits via their ancestry.
The more common examples are
HEAD^ = the parent of commit HEAD
HEAD~2 = traverses the first parent 2 times, finds the grand parent
What is an --interactive rebase?
Helps you clean up your private branches before publishing them
reword fixup
pick squash
edit exec
C O N F L I C T R E S O L U T I O N
A word on terminology
Current checked out branch
--ours
What do ours and theirs mean when solving conflicts?
Commit coming in (i.e. via merge)
--theirs
C O N F L I C T R E S O L U T I O N
Basics for easy conflict resolutionThe common commands are:
$ git checkout --ours/--theirs <file> Check back out our own/their own version of the file
$ git add <file> Add the change to the index will resolve the conflict
C O N F L I C T R E S O L U T I O N
Aliases for easy conflict resolutionAdd these to [alias] in .gitconfig:
ours = "!f() { \ \ }; f" git checkout --ours $@ && git add $@;
What is a merge?
Merge commit
master
feature
merges keep the context of the feature’s commits
feature
master
tree f362c42032aff677c1a09c3f070454df5b411239 parent 49a906f5722ad446a131778cea52e3fda331b706 parent bd1174cd0f30fe9be9efdd41dcd56256340f230e author Marcus Bertrand <[email protected]> 1409002123 -0700 committer Marcus Bertrand <[email protected]> 1409002123 -0700
Merge branch 'foo/mybranch'
.git/objects/36/80d8c8fd182f97cb0e75045e2fed5c7b7613ed
commit
Anatomy of a merge
Let’s talk about merge strategies!
git has breadth of choice on how to merge changes!
recursiveresolve octopus subtreeours yours?
Stage this hunk [y,n,q,a,d,/,s,e,?]? ? y - stage this hunk n - do not stage this hunk q - quit; do not stage this hunk or any of the remaining ones a - stage this hunk and all later hunks in the file d - do not stage this hunk or any later hunks in the file g - select a hunk to go to / - search for a hunk matching the given regex j - leave this hunk undecided, see next undecided hunk J - leave this hunk undecided, see next hunk k - leave this hunk undecided, see previous undecided hunk K - leave this hunk undecided, see previous hunk s - split the current hunk into smaller hunks e - manually edit the current hunk ? - print help
git stash is awesomeIt’s a way to temporarily store your
unsaved work on a stack of patches
stash@{0}
stash@{1}
stash@{2}
stash@{3}
git stash save