Slide 1

Slide 1 text

Git crash course: The collective noun for a group of programmers is a merge­conflict. Miklós Vajna 2013­09­27

Slide 2

Slide 2 text

2 / 27 LibreOffice Conference 2013 | Miklós Vajna Agenda ● Motivation ● Why version control? ● Why distributed version control? ● Why git? ● Git crash source ● A bottom­up introduction ● Contributing using git ● The LibreOffice perspective

Slide 3

Slide 3 text

Motivation

Slide 4

Slide 4 text

4 / 27 LibreOffice Conference 2013 | Miklós Vajna Why version control? ● Everyone uses version control: ● Think of 'Save As' ● Tarball + patches ● You can hardly avoid it if you collaborate ● Helps debugging ● Documentation tool

Slide 5

Slide 5 text

5 / 27 LibreOffice Conference 2013 | Miklós Vajna Why distributed version control? ● The full repo is available locally ● Fast diff, blame, log, merge ● You don't have to be always online ● No SPoF ● Concept of committer may go away ● Backups are less important ● Easier branch / merge

Slide 6

Slide 6 text

6 / 27 LibreOffice Conference 2013 | Miklós Vajna Why git? ● #1 reason is of course: it's distributed ● But still, a few other unique features ● git merge­recursive (e.g. cherry­pick handles renames) ● git rerere ● git blame – can detect the move of a code chunk ● git grep ● combined diff

Slide 7

Slide 7 text

Git crash course

Slide 8

Slide 8 text

8 / 27 LibreOffice Conference 2013 | Miklós Vajna A bottom­up introduction ● Low­level: content­addressable filesystem ● 4 object type: blob, tree, commit, tag ● Blob: one version of a file ● Tree: contains at least one tree(s) or blob(s) ● Commit: contains 0..many parents and 1 tree ● Also: message, date, name ● Tag: only used by annotated tags; can point to anything (usually points to a tag)

Slide 9

Slide 9 text

9 / 27 LibreOffice Conference 2013 | Miklós Vajna What is not an object ● Ref, symref ● Non­annotated tags are refs, not tag objects ● Hook ● Reflog ● Config ● Index

Slide 10

Slide 10 text

10 / 27 LibreOffice Conference 2013 | Miklós Vajna Merge vs. rebase ● At the beginning we have: ● Rebase: ● Merge: A B C F G D E topic master A B C F G D E topic master H A' B' C' F G D E topic master

Slide 11

Slide 11 text

11 / 27 LibreOffice Conference 2013 | Miklós Vajna Contributing using git ● By default, no push rights, sends patches ● Still works in git, locally ● Uses rebase, not merge ● Interactive rebase ● Squash, split, reorder patches ● git format­patch, git am, git review ● Bundles: offline transfer or merges

Slide 12

Slide 12 text

12 / 27 LibreOffice Conference 2013 | Miklós Vajna Commands: too many ● Which ones do I need? ● Current git (1.8.1.4) has 161 commands ● Categories: ● Main porcelain commands ● Ancillary porcelain commands ● Plumbing commands

Slide 13

Slide 13 text

13 / 27 LibreOffice Conference 2013 | Miklós Vajna Commands you will use ● init, clone, add, rm, mv ● status, branch, diff, log ● commit, reset (undo of commit and add) ● fetch, pull, push ● checkout, rebase, merge ● show, grep, bisect

Slide 14

Slide 14 text

14 / 27 LibreOffice Conference 2013 | Miklós Vajna Main porcelain commands ● archive, bundle, format­patch / am ● cherry­pick and revert ● describe, shortlog ● gc, clean, stash, submodule

Slide 15

Slide 15 text

15 / 27 LibreOffice Conference 2013 | Miklós Vajna Ancillary porcelain commands ● Manipulators: config, filter­branch ● Query: blame, fsck, verify­tag ● Talking to weird guys: ● fast­import / fast­export ● archimport, cvsimport/export ● quiltimport, svn

Slide 16

Slide 16 text

16 / 27 LibreOffice Conference 2013 | Miklós Vajna Porcelain commands ● For scripts, this is the stable API of git ● Example: log vs. rev­list $ git log --pretty=oneline HEAD~2.. 3b3e7061d610fa83d15b0ba66aba08fd7e39e611 fdo#66743 fix 5abc99f2fc9db8aa4dbce293898e26561f947ece Show errors $ git rev-list HEAD~2.. 3b3e7061d610fa83d15b0ba66aba08fd7e39e611 5abc99f2fc9db8aa4dbce293898e26561f947ece

Slide 17

Slide 17 text

17 / 27 LibreOffice Conference 2013 | Miklós Vajna Symbolic names of commits ● Scary example: ● What to remember: ^ and ~N. G H I J A = = A^0 \ / \ / B = A^ = A^1 = A~1 D E F C = A^2 = A^2 \ | / \ D = A^^ = A^1^1 = A~2 \ | / | E = B^2 = A^^2 \|/ | F = B^3 = A^^3 B C G = A^^^ = A^1^1^1 = A~3 \ / \ / A H = D^2 = B^^2 = A^^^2 = A~2^2 I = F^ = B^3^ = A^^3^ J = F^2 = B^3^2 = A^^3^2

Slide 18

Slide 18 text

18 / 27 LibreOffice Conference 2013 | Miklós Vajna The Index ● Problem: two changes to the same file, we want to commit only one of them ● Or during conflict resolution: resolve conflicts one by one Object store Working directory Index diff diff HEAD diff diff --cached

Slide 19

Slide 19 text

The LibreOffice perspective

Slide 20

Slide 20 text

20 / 27 LibreOffice Conference 2013 | Miklós Vajna Submodules ● Submodule: a tree references a commit ● When branches are matching, gerrit auto­ commits in core ● In LibreOffice, disabled by default ● Needed by: dictionaries, help, translations ● Pain: have to commit them separately ● Gain: no need to download them by default

Slide 21

Slide 21 text

21 / 27 LibreOffice Conference 2013 | Miklós Vajna Gerrit: the manual way ● Gerrit gives virtual push rights to everyone: ● git push origin HEAD:refs/for/master ● Change­Id footer makes it explicit what is the same change ● Cherry­picking form gerrit: ● git fetch origin refs/changes/12/6012/1 ● git cherry­pick FETCH_HEAD ● No hard dependency on external tools

Slide 22

Slide 22 text

22 / 27 LibreOffice Conference 2013 | Miklós Vajna Gerrit: helper tools ● git­review from OpenStack: ● Auto­setup based on .gitreview file ● git review: submits for review, prevents from accidental push of multiple commits ● git review ­x : cherry­pick from gerrit ● Packaged in most distributions ● logerrit: in­tree tool: ● ./logerrit submit ● ./logerrit cherry­pick

Slide 23

Slide 23 text

23 / 27 LibreOffice Conference 2013 | Miklós Vajna Referenced clone ● Only interesting if you build release branches as well ● git clone ­­reference /path/to/master ● If you use submodules as well: ● ./autogen.sh … ­­with­referenced­ git=/path/to/master ● Saving is significant, .git of master / release branch is like: 1.2GB / 13MB

Slide 24

Slide 24 text

24 / 27 LibreOffice Conference 2013 | Miklós Vajna Interactive rebase ● In LibreOffice's case, this is especially useful when doing unit testing: 1.Commit the fix 2.Commit the testcase once it passes 3.Revert the fix, make sure the testcase fails 4.Interactive rebase: – Drop the revert – Squash the commit and the testcase into one commit

Slide 25

Slide 25 text

25 / 27 LibreOffice Conference 2013 | Miklós Vajna Bisect: binary search ● Bisect in general is extremely useful for our large code­base, but there is more ● Bibisect: to avoid bisecting for a full day ● Reverse bisect: when you are checking what commit to backport to a release branch ● Swap bad and good in the git bisect start commandline ● Also swap git bisect bad and git bisect good

Slide 26

Slide 26 text

26 / 27 LibreOffice Conference 2013 | Miklós Vajna Push tree ● Create a referenced clone, called master­push ● Instead of push, cherry­pick to master­push, and push from there ● Avoids expensive rebuilds in the middle of your productive hours ● The less frequiently you pull in your master tree, the less useful it is (more conflicts) ● Still pull daily, weekly, etc. (depending on how fast your machine is)

Slide 27

Slide 27 text

27 / 27 LibreOffice Conference 2013 | Miklós Vajna Questions? ● Anyone? Slides: http://vmiklos.hu/odp