• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Dev conf git_lecture
 

Dev conf git_lecture

on

  • 513 views

 

Statistics

Views

Total Views
513
Views on SlideShare
381
Embed Views
132

Actions

Likes
0
Downloads
4
Comments
0

4 Embeds 132

http://juandebravo.com 99
http://feeds.feedburner.com 23
http://localhost 8
https://twitter.com 2

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Dev conf git_lecture Dev conf git_lecture Presentation Transcript

    • git internals Juan de Bravo @juandebravogit internals DevCon I 2012/11/27
    • Git. Definition Page 2 free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency git internals DevCon I 2012/11/27
    • Git. Distributed repository Page 3 git internals DevCon I 2012/11/27
    • Disclaimer Page 4 this talk is not about… git "usual commands" git workflow github/pdihub git internals DevCon I 2012/11/27
    • Disclaimer 2 Page 5 this talk is about… git internals DevCon I 2012/11/27
    • 1 git internals 2 git advanced topics 3 git tips & tricksgit internals DevCon I 2012/11/27
    • 1 git internals 2 git advanced topics 3 git tips & tricksgit internals DevCon I 2012/11/27
    • 1 git internals 1.1 git objects 1.2 git internal structuregit internals DevCon I 2012/11/27
    • 1 git internals 1.1 git objects 1.2 git internal structuregit internals DevCon I 2012/11/27
    • 1.1 git objects. types Page 10 git defines 4 object types - blobs : content - trees : content structure - commits: history snapshots - tags : named commits/objects git internals DevCon I 2012/11/27
    • 1.1 git objects. storage Page 11 These objects are stored individually inside the .git/objects folder λ find .git/objects | wc -l 628 λ find .git/objects | wc -l 1696 λ find .git/objects | wc -l 6543 git internals DevCon I 2012/11/27
    • 1.1 git objects. format and filename Page 12 git object format - object type: blob|tree|commit|tag - content size - null byte - content git object filename SHA1 of the previous format applied to the object git internals DevCon I 2012/11/27
    • 1 git internals 1.1 git objects 1.1.1 git blobgit internals DevCon I 2012/11/27
    • 1.1.1 git objects. blobs Page 14 Git stores every single file content using a blob object with the git format (object type, etc) <Blob SHA1> git internals DevCon I 2012/11/27
    • 1.1.1 git objects. blobs 3 Page 15 git hash-object git internals DevCon I 2012/11/27
    • 1.1.1 git objects. blobs 2 Page 16 $ echo Hello, world! > foo $ git hash-object foo af5626b4a114abcb82d63db7c8082c3c4756e51b $ git hash-object --stdin Hello, world! ^D af5626b4a114abcb82d63db7c8082c3c4756e51b Git stores every single file using a blob object with the predefined format. $ echo -en blob 140Hello, world!n | shasum af5626b4a114abcb82d63db7c8082c3c4756e51b git internals DevCon I 2012/11/27
    • 1.1.1 git objects. blobs. stdin Page 17 $ git init $ find .git/objects .git/objects .git/objects/info .git/objects/pack $ echo Hello, world! | git hash-object -w --stdin $ find .git/objects .git/objects .git/objects/af .git/objects/af/5626b4a114abcb82d63db7c8082c3c4756e51b .git/objects/info .git/objects/pack git internals DevCon I 2012/11/27
    • 1.1.1 git objects. blobs. file Page 18 $ git init $ find .git/objects .git/objects .git/objects/info .git/objects/pack $ echo Hello, world! > foo $ git add foo $ find .git/objects .git/objects .git/objects/af .git/objects/af/5626b4a114abcb82d63db7c8082c3c4756e51b .git/objects/info .git/objects/pack git internals DevCon I 2012/11/27
    • 1.1.1 git objects. blobs. cat-file 1 Page 19 git cat-file git internals DevCon I 2012/11/27
    • 1.1.1 git objects. blobs. cat-file Page 20 $ git cat-file -t af5626b4a114abcb82d63db7c8082c3c4756e51b blob $ git cat-file -s af5626b4a114abcb82d63db7c8082c3c4756e51b 14 $ git cat-file -p af5626b4a114abcb82d63db7c8082c3c4756e51b Hello, world! $ git cat-file blob af5626b4a114abcb82d63db7c8082c3c4756e51b Hello, world! git internals DevCon I 2012/11/27
    • 1.1.1 git objects. blobs. no file info Page 21 The following two commands are similar $ # porcelain $ echo Hello, world! > foo $ git add foo $ # plumbing $ echo Hello, world! | git hash-object -w --stdin In both cases, a blob object is created in .git/objects .git/objects/af/5626b4a114abcb82d63db7c8082c3c4756e51b git internals DevCon I 2012/11/27
    • 1.1.1 git objects. blobs. blob content Page 22 .foo foo Hello, world! .git/objects/af/5626b4a114abcb82d63db7c8082c3c4756e51b af 5626b4a114abcb82d63db7c8082c3c4756e51b af5626b blob 140Hello, world!n git internals DevCon I 2012/11/27
    • 1 git internals 1.1 git objects 1.1.2 git treesgit internals DevCon I 2012/11/27
    • 1.1.2 git objects. trees Page 24 Trees are used to: - store the filename of a specific file - store a group of files together <Tree SHA1> git internals DevCon I 2012/11/27
    • 1.1.2 git objects. trees 2 Page 25 # Add a file content to git $ echo Hello, world! > foo $ git add foo $ find .git/objects .git/objects .git/objects/af .git/objects/af/5626b4a114abcb82d63db7c8082c3c4756e51b .git/objects/info .git/objects/pack git internals DevCon I 2012/11/27
    • 1.1.2 git objects. create a tree Page 26 # Add a file content to git $ mkdir bar $ echo Hello, world! > bar/foo $ git add bar/foo $ find .git/objects .git/objects .git/objects/af .git/objects/af/5626b4a114abcb82d63db7c8082c3c4756e51b .git/objects/info .git/objects/pack git internals DevCon I 2012/11/27
    • 1.1.2 git objects. create a tree 2 Page 27 $ git commit -m first commit [master (root-commit) 83862bb] first commit 2 files changed, 2 insertions(+), 0 deletions(-) create mode 100644 bar/foo create mode 100644 foo git internals DevCon I 2012/11/27
    • 1.1.2 git objects. create a tree 3 Page 28 $ find .git/objects .git/objects .git/objects/83 .git/objects/83/862bbb8472f0b802be96b5e59993ca044f3c31 .git/objects/a8 .git/objects/a8/54cc8b798fb00ad0c3a7a63508b8cffe2e979b .git/objects/af .git/objects/af/5626b4a114abcb82d63db7c8082c3c4756e51b .git/objects/f2 .git/objects/f2/df5266567842bbb8a06acca56bcabf813cd73f .git/objects/info .git/objects/pack git internals DevCon I 2012/11/27
    • 1.1.2 git objects. create a tree 4 Page 29 $ git cat-file -t 83862bbb8472f0b802be96b5e59993ca044f3c31 commit $ git cat-file -t a854cc8b798fb00ad0c3a7a63508b8cffe2e979b tree $ git cat-file -t af5626b4a114abcb82d63db7c8082c3c4756e51b blob $ git cat-file -t f2df5266567842bbb8a06acca56bcabf813cd73f tree git internals DevCon I 2012/11/27
    • 1.1.2 git objects. create a tree 5 Page 30 git ls-tree git internals DevCon I 2012/11/27
    • 1.1.2 git objects. inspect a tree Page 31 $ git ls-tree a854cc8b798fb00ad0c3a7a63508b8cffe2e979b 040000 tree f2df5266567842bbb8a06acca56bcabf813cd73f bar 100644 blob af5626b4a114abcb82d63db7c8082c3c4756e51b foo $ git ls-tree f2df5266567842bbb8a06acca56bcabf813cd73f 100644 blob af5626b4a114abcb82d63db7c8082c3c4756e51b foo a854cc af5626 f2df52 af5626 git internals DevCon I 2012/11/27
    • 1.1.2 git objects. inspect a tree 2 Page 32 - Blobs does not store any file specific info - File specific info is stored in trees - Same operations, run in different computers, will create the same blobs/trees. git internals DevCon I 2012/11/27
    • 1.1.2 git objects. tree. plumbing Page 33 git update-index git write-tree git internals DevCon I 2012/11/27
    • 1.1.2 git objects. tree. plumbing 3 Page 34 A commit is the easiest way to create a tree, but it can be created manually (plumbing) $ git update-index --add --cacheinfo 100644 af5626b4a114abcb82d63db7c8082c3c4756e51b bazz $ git update-index --add --cacheinfo 100644 af5626b4a114abcb82d63db7c8082c3c4756e51b bazz2 $ git write-tree 0a5de923df76ac94a71800e28a4e449171073e3e git internals DevCon I 2012/11/27
    • 1.1.2 git objects. tree. plumbing 2 Page 35 $ find .git/objects 0a/5de923df76ac94a71800e28a4e449171073e3e af/5626b4a114abcb82d63db7c8082c3c4756e51b $ git ls-tree 0a5de923df76ac94a71800e28a4e449171073e3e 100644 blob af5626b4a114abcb82d63db7c8082c3c4756e51b bazz 100644 blob af5626b4a114abcb82d63db7c8082c3c4756e51b bazz2 0a5de9 af5626 af5626 git internals DevCon I 2012/11/27
    • 1 git internals 1.1 git objects 1.1.3 git commitgit internals DevCon I 2012/11/27
    • 1.1.3 git objects. commits Page 37 Create a snapshot of the current status of the repository <Commit-SHA1> git internals DevCon I 2012/11/27
    • 1.1.3 git objects. commits 2 Page 38 $ git commit -m first commit [master (root-commit) 83862bb] first commit 2 files changed, 2 insertions(+), 0 deletions(-) create mode 100644 bar/foo create mode 100644 foo $ find .git/objects .git/objects .git/objects/83 .git/objects/83/862bbb8472f0b802be96b5e59993ca044f3c31 .git/objects/a8 .git/objects/a8/54cc8b798fb00ad0c3a7a63508b8cffe2e979b .git/objects/af .git/objects/af/5626b4a114abcb82d63db7c8082c3c4756e51b .git/objects/f2 .git/objects/f2/df5266567842bbb8a06acca56bcabf813cd73f .git/objects/info .git/objects/pack git internals DevCon I 2012/11/27
    • 1.1.3 git objects. commits 3 Page 39 $ git cat-file -p 83862bb tree a854cc8b798fb00ad0c3a7a63508b8cffe2e979b author juandebravo <juandebravo@gmail.com> 1353253703 +0100 committer juandebravo <juandebravo@gmail.com> 1353253703 +0100 first commit $ git ls-tree HEAD $ git cat-file -p a854cc8b $ git cat-file -p "master^{tree}" 040000 tree f2df5266567842bbb8a06acca56bcabf813cd73f bar 100644 blob af5626b4a114abcb82d63db7c8082c3c4756e51b foo git internals DevCon I 2012/11/27
    • 1.1.3 git objects. commits 4 Page 40 83862bb a854cc8 af5626b f2df526 af5626b git internals DevCon I 2012/11/27
    • 1 git internals 1.1 git objects 1.1.4 git taggit internals DevCon I 2012/11/27
    • 1.1.4 git objects. tags. lightweight tag Page 42 lightweight tag Similar to a commit, but points to a commit rather than to a tree Like a branch reference, but it never moves git internals DevCon I 2012/11/27
    • 1.1.4 git objects. tags. lightweight tag 1 Page 43 λ git tag v1.0 λ git cat-file -p v1.0 tree dba14fbffe61ae959c139d847fcf7709ac7f03d5 parent 83862bbb8472f0b802be96b5e59993ca044f3c31 author juandebravo <juandebravo@gmail.com> 1353954525 +0100 committer juandebravo <juandebravo@gmail.com> 1353954525 +0100 git internals DevCon I 2012/11/27
    • 1.1.4 git objects. tags. annotated tag Page 44 annotated tag Stored as full objects: - checksum - tagger name, email, date - comment - can be signed and verified git internals DevCon I 2012/11/27
    • 1.1.4 git objects. tags. anotated tag Page 45 λ git tag -a v1.1 -m "version 1.1" λ git cat-file -p v1.1 object c2120756cce9f359373d2fd42f8eac5cd5f9cbe9 type commit tag v1.1 tagger juandebravo <juandebravo@gmail.com> Tue Nov 22 17:42:02 2012 +0100 version 1.1 git internals DevCon I 2012/11/27
    • 1.1.4 git objects. tags. anotated tag 2 Page 46 λ cd CONNECT/tid-commons λ ls -l total 32 -rw-r--r-- 1 jdbd staff 1594 27 Nov 07:47 LICENSE.txt -rw-r--r-- 1 jdbd staff 1909 27 Nov 07:47 README.md drwxr-xr-x 2 jdbd staff 68 22 Aug 13:21 dist -rw-r--r-- 1 jdbd staff 114 30 Oct 23:53 setup.cfg -rw-r--r-- 1 jdbd staff 312 27 Nov 07:47 setup.py drwxr-xr-x 18 jdbd staff 612 27 Nov 07:47 tests drwxr-xr-x 24 jdbd staff 816 27 Nov 07:47 tid_commons git internals DevCon I 2012/11/27
    • 1.1.4 git objects. tags. anotated tag 3 Page 47 λ git ls-tree HEAD100644 blob 0d20b6487c61e7d1bde93acf4a14b7a89083a16d .gitignore100644 blob a27144556d3b857a6fb609f39be204996e1f7792 LICENSE.txt100644 blob 15446c94618f3863584814d669048dc3def789cf README.md100644 blob b6c8d6c27ce614109dcb07b2e655ce13727675fa setup.cfg100644 blob 6ee4913e18e4a6a2320ac1e540a585f12bc110b2 setup.py040000 tree a7c28bc15f440bcf3783915f24ff3336b81dd01f tests040000 tree 35ea155eb6899a337b1b0ed5307d0882a0b7858e tid_commons git internals DevCon I 2012/11/27
    • 1.1.4 git objects. tags. anotated tag 4 Page 48 λ git tag -a LICENSE a2714455 -m "License file" λ git cat-file -p LICENSE object a27144556d3b857a6fb609f39be204996e1f7792 type blob tag LICENSE tagger juandebravo <juandebravo@gmail.com> Tue Nov 27 07:48:36 2012 +0100 License file git internals DevCon I 2012/11/27
    • 1 git internals 1.1 git objects 1.2 git internal structuregit internals DevCon I 2012/11/27
    • 1.2 git internal structure Page 50 .git !"" COMMIT_EDITMSG !"" objects !"" HEAD #   !"" 83 !"" branches #   #   $"" 862bbb8472f0b802be96b5e59993ca044f3c31 !"" config #   !"" a8 !"" description #   #   $"" 54cc8b798fb00ad0c3a7a63508b8cffe2e979b !"" hooks #   !"" af !"" index #   #   $"" 5626b4a114abcb82d63db7c8082c3c4756e51b !"" info #   !"" f2 #   $"" exclude #   #   $"" df5266567842bbb8a06acca56bcabf813cd73f !"" logs #   !"" info #   !"" HEAD #   $"" pack #   $"" refs $"" refs #   $"" heads !"" heads #   $"" master #   $"" master $"" tags git internals DevCon I 2012/11/27
    • 1.2.1 git internal structure. HEAD 1 Page 51 HEAD reference to current checkout commit git internals DevCon I 2012/11/27
    • 1.2.1 git internal structure. HEAD 2 Page 52 $ git status # On branch master nothing to commit (working directory clean) $ cat .git/HEAD ref: refs/heads/master git internals DevCon I 2012/11/27
    • 1.2.1 git internal structure. HEAD 3 Page 53 $ git branch feature/memoize_client $ cat .git/HEAD ref: refs/heads/master $ git checkout feature/memoize_client $ cat .git/HEAD ref: refs/heads/feature/memoize/client git internals DevCon I 2012/11/27
    • 1.2.1 git internal structure. HEAD 4 Page 54 # Check where HEAD is pointing to $ git symbolic-ref HEAD refs/heads/feature/memoize/client # Modify HEAD $ git symbolic-ref HEAD refs/head/master $ cat .git/HEAD refs/heads/master git internals DevCon I 2012/11/27
    • 1.2.1 git internal structure. HEAD 5 Page 55 # Example. zsh # get the name of the branch we are on function git_prompt_info() { ref=$(git symbolic-ref HEAD 2> /dev/null) || return echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$ (parse_git_dirty)$ZSH_THEME_GIT_PROMPT_SUFFIX" } juandebravo [~/projects/git_internals/repo] (master) ✓ git internals DevCon I 2012/11/27
    • 1.2.2 git internal structure. config Page 56 CONFIG repository specific configuration git internals DevCon I 2012/11/27
    • 1.2.2 git internal structure. config 2 Page 57 λ cat .git/config [core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true ignorecase = true git internals DevCon I 2012/11/27
    • 1.2.2 git internal structure. REFS Page 58 REFS reference to tags and branches commits git internals DevCon I 2012/11/27
    • 1.2.2 git internal structure. REFS 2 Page 59 !"" objects #   !"" 83 #   #   $"" 862bbb8472f0b802be96b5e59993ca044f3c31 #   !"" a8 #   #   $"" 54cc8b798fb00ad0c3a7a63508b8cffe2e979b #   !"" af #   #   $"" 5626b4a114abcb82d63db7c8082c3c4756e51b #   !"" f2 #   #   $"" df5266567842bbb8a06acca56bcabf813cd73f #   !"" info #   $"" pack $"" refs !"" heads #   $"" feature #   #   $"" memoize_client #   $"" master $"" tags git internals DevCon I 2012/11/27
    • 1.2.2 git internal structure. REFS 3 Page 60 λ find .git/refs .git/refs .git/refs/heads .git/refs/heads/feature .git/refs/heads/feature/memoize_client .git/refs/heads/master .git/refs/tags git internals DevCon I 2012/11/27
    • 1.2.2 git internal structure. REFS 5 Page 61 λ cat .git/refs/heads/feature/memoize_client 83862bbb8472f0b802be96b5e59993ca044f3c31 λ cat .git/refs/heads/master 83862bbb8472f0b802be96b5e59993ca044f3c31 λ git cat-file -p 83862bbb8472f0b802be96b5e59993ca044f3c31 tree a854cc8b798fb00ad0c3a7a63508b8cffe2e979b author juandebravo <juandebravo@gmail.com> 1353253703 +0100 committer juandebravo <juandebravo@gmail.com> 1353253703 +0100 first commit git internals DevCon I 2012/11/27
    • 1.2.2 git internal structure. REFS 6 Page 62 λ git checkout feature/memoize_client λ echo "¿Cómo están ustedes?" >> foo λ git commit -am "miliki, we love you" [feature/memoize_client 7d52f00] miliki, we love you 1 files changed, 2 insertions(+), 0 deletions(-) git internals DevCon I 2012/11/27
    • 1.2.2 git internal structure. REFS 7 Page 63 λ cat .git/refs/heads/feature/memoize_client 7d52f0083ebf11fdfd4ea00f6806e29fd8089ab2 λ cat .git/refs/heads/master 83862bbb8472f0b802be96b5e59993ca044f3c31 git internals DevCon I 2012/11/27
    • 1.2.2 git internal structure. REFS 8 Page 64 λ git log 7d52f00 - (HEAD, feature/memoize_client) miliki, we love you - juandebravo (15 minutes ago) 83862bb - (master) first commit - juandebravo (8 days ago) git internals DevCon I 2012/11/27
    • 1.2.2 git internal structure. REFS 9 Page 65 λ git log 7d52f00 - (HEAD, feature/memoize_client) miliki, we love you - juandebravo (15 minutes ago) 83862bb - (master) first commit - juandebravo (8 days ago) λ git tag v1.0 7d52f00 - (HEAD, v1.0, feature/memoize_client) miliki, we love you - juandebravo (15 minutes ago) 83862bb - (master) first commit - juandebravo (8 days ago) git internals DevCon I 2012/11/27
    • 1.2.2 git internal structure. REFS 10 Page 66 λ find .git/refs .git/refs .git/refs/heads .git/refs/heads/feature .git/refs/heads/feature/memoize_client .git/refs/heads/master .git/refs/tags .git/refs/tags/v1.0 git internals DevCon I 2012/11/27
    • 1.2.2 git internal structure. REFS 11 Page 67 λ cat .git/refs/tags/v1.0 7d52f0083ebf11fdfd4ea00f6806e29fd8089ab2 λ echo "Bieeeeeeeeen" >> foo λ git commit -am "yet another commit" [feature/memoize_client c212075] yet another commit 1 files changed, 1 insertions(+), 0 deletions(-) git internals DevCon I 2012/11/27
    • 1.2.2 git internal structure. REFS 12 Page 68 λ git log c212075 - (HEAD, feature/memoize_client) yet another commit - juandebravo (87 seconds ago) 7d52f00 - (v1.0) miliki, we love you - juandebravo (25 minutes ago) 83862bb - (master) first commit - juandebravo (8 days ago) git internals DevCon I 2012/11/27
    • 1 git internals 2 git advanced topics 3 git tips & tricksgit internals DevCon I 2012/11/27
    • 2 git advanced topics 2.1 git bisect 2.2 git reflog 2.3 git stashgit internals DevCon I 2012/11/27
    • 2 git advanced topics 2.1 git bisect 2.2 git reflog 2.3 git stashgit internals DevCon I 2012/11/27
    • 2.1 git bisect Page 72 The bisect command does a binary search through your commit history to help you identify as quickly as possible which commit introduced an issue. git internals DevCon I 2012/11/27
    • 2.1 git bisect 17 Page 73 git internals DevCon I 2012/11/27
    • 2.1 git bisect 2 Page 74 λ tree . !"" main #   !"" __init__.py #   $"" foo.py $"" tests $"" foo_tests.py git internals DevCon I 2012/11/27
    • 2.1 git bisect 3 Page 75 import re reg_expr = re.compile(^d{,10}$) class Foo(object): @staticmethod def is_valid(value): _value = reg_expr.match(str(value)) return True if _value else False git internals DevCon I 2012/11/27
    • 2.1 git bisect 4 Page 76 import unittest from pyshould import should from main.foo import Foo class TestFoo(unittest.TestCase): def setUp(self): self.foo = Foo def test_is_valid_string(self): self.foo.is_valid(1234) | should.be_true def test_is_valid_number(self): self.foo.is_valid(1234) | should.be_true def test_is_valid_one_digit(self): self.foo.is_valid(1) | should.be_true git internals DevCon I 2012/11/27
    • 2.1 git bisect 5 Page 77 λ nosetests -sv test_is_valid_number (foo_tests.TestFoo) ... ok test_is_valid_one_digit (foo_tests.TestFoo) ... ok test_is_valid_string (foo_tests.TestFoo) ... ok --------------------------------------------------------- Ran 3 tests in 0.013s OK git internals DevCon I 2012/11/27
    • 2.1 git bisect 6 Page 78 λ git lg * 2ca0083 - (HEAD, master) change regepx - juandebravo (12 minutes ago) * 1824e4f - change regepx - juandebravo (12 minutes ago) * 898489c - change regepx - juandebravo (12 minutes ago) * f683803 - change regepx - juandebravo (12 minutes ago) * dbe4c2e - change regepx - juandebravo (12 minutes ago) * ec56109 - change regepx - juandebravo (12 minutes ago) * 14b0d5f - change regepx - juandebravo (13 minutes ago) * 938a43b - change regepx - juandebravo (13 minutes ago) * bb9f17a - change regepx - juandebravo (13 minutes ago) * a8aa38f - change regepx - juandebravo (13 minutes ago) * 74e307f - remove pyc files - juandebravo (2 hours ago) * 82e49f3 - fix .gitignore - juandebravo (2 hours ago) * 9a8bdf8 - first commit - juandebravo (2 hours ago) git internals DevCon I 2012/11/27
    • 2.1 git bisect 7 Page 79 λ nosetests -sv test_is_valid_number (foo_tests.TestFoo) ... FAIL test_is_valid_one_digit (foo_tests.TestFoo) ... ok test_is_valid_string (foo_tests.TestFoo) ... FAIL ------------------------------------------------------- Ran 3 tests in 0.013s FAILED (failures=2) git internals DevCon I 2012/11/27
    • 2.1 git bisect 8 Page 80 git bisect is your friend 1) Figure out a commit that was right: good commit 2) Figure out a commit that is wrong: the current one, bad commit 3) run git bisect command git internals DevCon I 2012/11/27
    • 2.1 git bisect 9 Page 81 λ git lg * dc46efc - (HEAD, master) add unittest main - juandebravo (4 minutes ago) * 2ca0083 - change regepx - juandebravo (12 minutes ago) * 1824e4f - change regepx - juandebravo (12 minutes ago) * 898489c - change regepx - juandebravo (12 minutes ago) * f683803 - change regepx - juandebravo (12 minutes ago) * dbe4c2e - change regepx - juandebravo (12 minutes ago) * ec56109 - change regepx - juandebravo (12 minutes ago) * 14b0d5f - change regepx - juandebravo (13 minutes ago) * 938a43b - change regepx - juandebravo (13 minutes ago) * bb9f17a - change regepx - juandebravo (13 minutes ago) * a8aa38f - change regepx - juandebravo (13 minutes ago) * 74e307f - remove pyc files - juandebravo (2 hours ago) * 82e49f3 - fix .gitignore - juandebravo (2 hours ago) * 9a8bdf8 - first commit - juandebravo (2 hours ago) git internals DevCon I 2012/11/27
    • 2.1 git bisect 18 Page 82 reg = r^s*(?=^.{7,}$)(?=.*[a-zA-Z])(?=.*d)(?!.*s).*?s*$ reg_expr = re.compile(reg) git internals DevCon I 2012/11/27
    • 2.1 git bisect 10 Page 83 λ git bisect start HEAD 9a8bdf8 Bisecting: 5 revisions left to test after this (roughly 3 steps) [ec56109cc441293571a0773c83006afe483ff0e6] change regepx git internals DevCon I 2012/11/27
    • 2.1 git bisect 11 Page 84 λ git lg * dc46efc - (HEAD, master) add unittest main - juandebravo (4 minutes ago) * 2ca0083 - change regepx - juandebravo (12 minutes ago) * 1824e4f - change regepx - juandebravo (12 minutes ago) * 898489c - change regepx - juandebravo (12 minutes ago) * f683803 - change regepx - juandebravo (12 minutes ago) * dbe4c2e - change regepx - juandebravo (12 minutes ago) * ec56109 - change regepx - juandebravo (12 minutes ago) * 14b0d5f - change regepx - juandebravo (13 minutes ago) * 938a43b - change regepx - juandebravo (13 minutes ago) * bb9f17a - change regepx - juandebravo (13 minutes ago) * a8aa38f - change regepx - juandebravo (13 minutes ago) * 74e307f - remove pyc files - juandebravo (2 hours ago) * 82e49f3 - fix .gitignore - juandebravo (2 hours ago) * 9a8bdf8 - first commit - juandebravo (2 hours ago) git internals DevCon I 2012/11/27
    • 2.1 git bisect 12 Page 85 $ git bisect run nosetests -sv Ran 3 tests in 0.014s OK Bisecting: 2 revisions left to test after this (roughly 2 steps) [898489c1e7b77989717a84f08f49f43cf215c120] change regepx git internals DevCon I 2012/11/27
    • 2.1 git bisect 19 Page 86 λ git lg * dc46efc - (HEAD, master) add unittest main - juandebravo (4 minutes ago) * 2ca0083 - change regepx - juandebravo (12 minutes ago) * 1824e4f - change regepx - juandebravo (12 minutes ago) * 898489c - change regepx - juandebravo (12 minutes ago) * f683803 - change regepx - juandebravo (12 minutes ago) * dbe4c2e - change regepx - juandebravo (12 minutes ago) * ec56109 - change regepx - juandebravo (12 minutes ago) * 14b0d5f - change regepx - juandebravo (13 minutes ago) * 938a43b - change regepx - juandebravo (13 minutes ago) * bb9f17a - change regepx - juandebravo (13 minutes ago) * a8aa38f - change regepx - juandebravo (13 minutes ago) * 74e307f - remove pyc files - juandebravo (2 hours ago) * 82e49f3 - fix .gitignore - juandebravo (2 hours ago) * 9a8bdf8 - first commit - juandebravo (2 hours ago) git internals DevCon I 2012/11/27
    • 2.1 git bisect 13 Page 87 ---------------------------------------------------------- Ran 3 tests in 0.014s FAILED (failures=2) Bisecting: 0 revisions left to test after this (roughly 1 step) [f6838032010b18a7e3998f4a2fdcde65124424a2] change regepx git internals DevCon I 2012/11/27
    • 2.1 git bisect 20 Page 88 λ git lg * dc46efc - (HEAD, master) add unittest main - juandebravo (4 minutes ago) * 2ca0083 - change regepx - juandebravo (12 minutes ago) * 1824e4f - change regepx - juandebravo (12 minutes ago) * 898489c - change regepx - juandebravo (12 minutes ago) * f683803 - change regepx - juandebravo (12 minutes ago) * dbe4c2e - change regepx - juandebravo (12 minutes ago) * ec56109 - change regepx - juandebravo (12 minutes ago) * 14b0d5f - change regepx - juandebravo (13 minutes ago) * 938a43b - change regepx - juandebravo (13 minutes ago) * bb9f17a - change regepx - juandebravo (13 minutes ago) * a8aa38f - change regepx - juandebravo (13 minutes ago) * 74e307f - remove pyc files - juandebravo (2 hours ago) * 82e49f3 - fix .gitignore - juandebravo (2 hours ago) * 9a8bdf8 - first commit - juandebravo (2 hours ago) git internals DevCon I 2012/11/27
    • 2.1 git bisect 14 Page 89 ---------------------------------------------------------- Ran 3 tests in 0.013s OK 898489c1e7b77989717a84f08f49f43cf215c120 is the first bad commit commit 898489c1e7b77989717a84f08f49f43cf215c120 Author: juandebravo <juandebravo@gmail.com> Date: Mon Nov 26 21:48:50 2012 +0100 change regepx :040000 040000 70ccfdcf5d796cbd581a840c1c92ebe47b40345e 3912c8faed49a91e6fe3f68e7370a86c120c2844 M main bisect run success git internals DevCon I 2012/11/27
    • 2.1 git bisect 15 Page 90 λ git lg * dc46efc - (master) add unittest main - juandebravo (4 minutes ago) * 2ca0083 - change regepx - juandebravo (49 minutes ago) * 1824e4f - change regepx - juandebravo (49 minutes ago) * 898489c - (refs/bisect/bad) change regepx - juandebravo (49 minutes ago) * f683803 - (HEAD, refs/bisect/good-f6838032010b18a7e3998f4a2fdcde65124424a2) change regepx - juandebravo (49 minutes * dbe4c2e - change regepx - juandebravo (49 minutes ago) * ec56109 - (refs/bisect/good-ec56109cc441293571a0773c83006afe483ff0e6) change regepx - juandebravo (50 minutes ago) * 14b0d5f - change regepx - juandebravo (50 minutes ago) * 938a43b - change regepx - juandebravo (50 minutes ago) * bb9f17a - change regepx - juandebravo (50 minutes ago) * a8aa38f - change regepx - juandebravo (50 minutes ago) * 74e307f - (refs/bisect/good-74e307f9003e661f3c5e5f9697915d2a1de2e96e) remove pyc files - juandebravo (2 hours ago) * 82e49f3 - fix .gitignore - juandebravo (2 hours ago) * 9a8bdf8 - first commit - juandebravo (2 hours ago) git internals DevCon I 2012/11/27
    • 2.1 git bisect 16 Page 91 Reset: remove bisect information from history λ git bisect reset Previous HEAD position was f683803... change regepx Switched to branch master git internals DevCon I 2012/11/27
    • 2 git advanced topics 2.1 git bisect 2.2 git reflog 2.3 git stashgit internals DevCon I 2012/11/27
    • 2.2 git reflog Page 93 A log of where your HEAD and branch references have been for the last few months. git internals DevCon I 2012/11/27
    • 2.2 git reflog 4 Page 94 It persists independently of other changes in your repository. I could unlink any commit from my repository (using reset), yet it would still be referenced by the reflog for another 30 days! git internals DevCon I 2012/11/27
    • 2.2 git reflog 2 Page 95 $ git reflog dc46efc HEAD@{0}: checkout: moving from 2ca0083fc6ba6bdfbf3000122eba51359309ae7f to master 2ca0083 HEAD@{1}: checkout: moving from master to HEAD@{22} dc46efc HEAD@{2}: checkout: moving from 1824e4fdcf1fc963554b2ae671ede799a692838a to master 1824e4f HEAD@{3}: checkout: moving from ec56109cc441293571a0773c83006afe483ff0e6 to HEAD@{36} ec56109 HEAD@{4}: checkout: moving from master to HEAD@{70} dc46efc HEAD@{5}: checkout: moving from f6838032010b18a7e3998f4a2fdcde65124424a2 to master f683803 HEAD@{6}: checkout: moving from 898489c1e7b77989717a84f08f49f43cf215c120 to f6838032010b18a7e3998f4a2fdcde651 898489c HEAD@{7}: checkout: moving from ec56109cc441293571a0773c83006afe483ff0e6 to 898489c1e7b77989717a84f08f49f43cf ec56109 HEAD@{8}: checkout: moving from master to ec56109cc441293571a0773c83006afe483ff0e6 dc46efc HEAD@{9}: checkout: moving from master to master dc46efc HEAD@{10}: checkout: moving from a8aa38f28e9bc76bdc73603b73f1a31a674b28dd to master git internals DevCon I 2012/11/27
    • 2.2 git reflog 3 Page 96 $ git show HEAD@{5} $ git show master@{2.months.ago} git internals DevCon I 2012/11/27
    • 2 git advanced topics 2.1 git rebase 2.2 git bisect 2.3 git stashgit internals DevCon I 2012/11/27
    • 2.3 git stash 9 Page 98 Imagine this scenario... git internals DevCon I 2012/11/27
    • 2.3 git stash Page 99 1) you are working in a cool user story 2) a JIRA task is assigned to you git internals DevCon I 2012/11/27
    • 2.3 git stash 11 Page 100 1) you are working in a cool user story 2) a JIRA task is assigned to you 3) JIRA is down git internals DevCon I 2012/11/27
    • 2.3 git stash 10 Page 101 1) you are working in a cool user story 2) a JIRA task is assigned to you 3) JIRA is down 4) coffee while JIRA comes back to life 5) you figure out what you should do 6) you need to switch to another branch 7) but you dont want to commit half-work git internals DevCon I 2012/11/27
    • 2.3 git stash 2 Page 102 git internals DevCon I 2012/11/27
    • 2.3 git stash 3 Page 103 λ git status # On branch master # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: main/foo.py # no changes added to commit (use "git add" and/or "git commit -a") git internals DevCon I 2012/11/27
    • 2.3 git stash 4 Page 104 λ git stash Saved working directory and index state WIP on master: dc46efc add unittest main HEAD is now at dc46efc add unittest main λ git stash list stash@{0}: WIP on master: dc46efc add unittest main git internals DevCon I 2012/11/27
    • 2.3 git stash 5 Page 105 λ git lg * 7cf1d41 - (refs/stash) WIP on master: dc46efc add main - juandebravo (6 minutes ago) | | * 7bcc6de - index on master: dc46efc add unittest main - juandebravo (6 minutes ago) |/ * dc46efc - (HEAD, master) add unittest main - juandebravo (46 minutes ago) * 2ca0083 - change regepx - juandebravo (2 hours ago) * 1824e4f - change regepx - juandebravo (2 hours ago) * 898489c - change regepx - juandebravo (2 hours ago) git internals DevCon I 2012/11/27
    • 2.3 git stash 6 Page 106 λ git cat-file commit 7cf1d41 tree f1d28d6483820c19e43bc17d46f3a9ab393aba6f parent dc46efcfa8fee91b94ed40d78e8b43f7afc53196 parent 7bcc6de1d49f8113d019e2c45b87938363bb54bd author juandebravo <juandebravo@gmail.com> 1353968043 +0100 committer juandebravo <juandebravo@gmail.com> 1353968043 +0100 WIP on master: dc46efc add unittest main git internals DevCon I 2012/11/27
    • 2.3 git stash 7 Page 107 λ git cat-file commit 7bcc6de tree 71d53f971a4924e0cec9264a0774ba63a6eba3b9 parent dc46efcfa8fee91b94ed40d78e8b43f7afc53196 author juandebravo <juandebravo@gmail.com> 1353968043 +0100 committer juandebravo <juandebravo@gmail.com> 1353968043 +0100 index on master: dc46efc add unittest main git internals DevCon I 2012/11/27
    • 2.3 git stash 8 Page 108 λ git stash list stash@{0}: WIP on master: dc46efc add unittest main λ cat .git/refs/stash 7cf1d41c1352d4df176d53d566354b8ca4d517cd git internals DevCon I 2012/11/27
    • 1 git internals 2 git advanced topics 3 git tips & tricksgit internals DevCon I 2012/11/27
    • 3. git tips and tricks Page 110 WORK WITH MORE THAN ONE REMOTE git internals DevCon I 2012/11/27
    • 3. git tips and tricks 2 Page 111 0) Fork repository 1) Clone repository $ git clone git@pdihub.hi.inet:jdbd/txsip.git $ git remote -v origin git@pdihub.hi.inet:jdbd/txsip.git (fetch) origin git@pdihub.hi.inet:jdbd/txsip.git (push) git internals DevCon I 2012/11/27
    • 3. git tips and tricks 4 Page 112 2) Add upstream repository $ git remote add upstream git@pdihub.hi.inet:ggb/txsip.git $ git remote -v origin git@pdihub.hi.inet:jdbd/txsip.git (fetch) origin git@pdihub.hi.inet:jdbd/txsip.git (push) upstream git@pdihub.hi.inet:ggb/txsip.git (fetch) upstream git@pdihub.hi.inet:ggb/txsip.git (push) git internals DevCon I 2012/11/27
    • 3. git tips and tricks 3 Page 113 3) Work... $ git checkout -b task/minor_changes .. git commit -m "bla bla" git push origin task/minor_changes 4) Pull request... git internals DevCon I 2012/11/27
    • 3. git tips and tricks 5 Page 114 5) Your pull request is accepted by the upstream repo owner (thanks @ggb) git internals DevCon I 2012/11/27
    • 3. git tips and tricks 6 Page 115 6) Fetch and sync changes $ git fetch upstream $ git checkout master $ git merge upstream/master Updating c87ea52..eec65b1 Fast-forward .gitignore | 1 + README.md | 2 +- libs/pjsua.pyc | Bin 104192 -> 100106 bytes txsip/__init__.py | 1 + txsip.py => txsip/main.py | 0 5 files changed, 3 insertions(+), 1 deletions(-) create mode 100644 .gitignore create mode 100644 txsip/__init__.py rename txsip.py => txsip/main.py (100%) git internals DevCon I 2012/11/27
    • 3. git tips and tricks 7 Page 116 7) Push changes to origin git push origin master git lg * eec65b1 - (HEAD, upstream/master, origin/master, origin/HEAD, master) Merge pull request #2 from jdbd/task/minor_ | | * f9e29a5 - (origin/task/minor_changes) PDI folder structure - juandebravo (4 days ago) | * 4b653ac - fix typo - juandebravo (4 days ago) | * 100a3db - create .gitignore file - juandebravo (4 days ago) | * 41ea559 - remove *.pyc - juandebravo (4 days ago) |/ * c87ea52 - UPDATE packet size limit in pjsip - ggb (5 weeks ago) git internals DevCon I 2012/11/27
    • 3. git tips and tricks 8 Page 117 HIGHLIGHT YOUR SHELL git internals DevCon I 2012/11/27
    • 3. git tips and tricks 9 Page 118 git internals DevCon I 2012/11/27
    • 3. git tips and tricks 12 Page 119 USE .GITCONFIG git internals DevCon I 2012/11/27
    • 3. git tips and tricks 13 Page 120 [user] name = juandebravo email = juandebravo@gmail.com [alias] lg= log --graph --abbrev-commit --date=relative --all co = checkout br = branch ci = commit st = status db = branch -d unstage = reset HEAD -- last = log -1 HEAD release = !"sh -c git checkout -b release/$1 develop" git internals DevCon I 2012/11/27
    • 3. git tips and tricks 14 Page 121 git internals DevCon I 2012/11/27
    • git internals git advanced topics Juan de Bravo Questions?git internals DevCon I 2012/11/27