|  | 1 | [[TOC]] | 
          
            |  | 2 |  | 
          
            |  | 3 | Back to [ProvideFix How To Provide A Fix]. | 
          
            |  | 4 |  | 
          
            |  | 5 | == Why git bundles == | 
          
            |  | 6 |  | 
          
            |  | 7 | Currently, the repo is folded into different public branches, letting a contributor choose on which of these branch his new patch is meant to be applied (see [patchesRasdamanReleaseProcess#Branchingmodel here] for details]. | 
          
            |  | 8 |  | 
          
            |  | 9 | This wiki page is meant for developers who need to reflect a ''merge'' operations to the public repo: indeed a solution which provides both un-linearized history and submission to the [patchmanagaer patch manager] is to submit a ''bundle''. | 
          
            |  | 10 |  | 
          
            |  | 11 | This allows no behind-the-scenes merge operations, and at the same time reflects the actual merge in the history of the repo, which otherwise won't be visible with patches: | 
          
            |  | 12 |  | 
          
            |  | 13 | * REPO STATUS BEFORE MERGE : | 
          
            |  | 14 | {{{ | 
          
            |  | 15 | o-------A------B   master | 
          
            |  | 16 | \ | 
          
            |  | 17 | C-------D   feature_X | 
          
            |  | 18 | }}} | 
          
            |  | 19 | * REPO STATUS AFTER MERGING BUNDLE : | 
          
            |  | 20 | {{{ | 
          
            |  | 21 | o-------A------B------M   master | 
          
            |  | 22 | \           / | 
          
            |  | 23 | C---------D   feature_X | 
          
            |  | 24 | }}} | 
          
            |  | 25 | * REPO STATUS AFTER MERGING PATCH : | 
          
            |  | 26 | {{{ | 
          
            |  | 27 | o-------A------B------P   master | 
          
            |  | 28 | \ | 
          
            |  | 29 | C---------D   feature_X | 
          
            |  | 30 | }}} | 
          
            |  | 31 |  | 
          
            |  | 32 | Although git bundles are pretty powerful, that is they can add commits, merge branches, etc. It is important here to follow some rules when submitting a bundle, which mainly are: | 
          
            |  | 33 |  | 
          
            |  | 34 | * HONESTY:[[BR]] | 
          
            |  | 35 | Each patch must be associated to a ticket (see [StandardsAndGuideLines guidelines]), hence a git bundle should '''only perform the merge''' of two branches: no new "patches" should be stacked in, in none of the two branches (number of refs in the bundle will be checked anyway by the patch manager); | 
          
            |  | 36 | * NAMING CONVENTIONS | 
          
            |  | 37 | * the name of the merging '''commit''' must follow the naming convention "`Merge branch 'feature_X' into master`", so actually leave the default title that git sets; | 
          
            |  | 38 | * the name of the '''bundle file''' must follow the pattern "`ticket:NNN_descriptionOfMerge.bundle`", referring to the ticket which justifies the merge. | 
          
            |  | 39 |  | 
          
            |  | 40 | == Creating and submitting a bundle == | 
          
            |  | 41 |  | 
          
            |  | 42 | When it's time to merge a branch which is publicly available, the situation can be very painful, but this is [http://weblog.masukomi.org/2008/07/12/handling-and-avoiding-conflicts-in-git another story]. | 
          
            |  | 43 |  | 
          
            |  | 44 | First of all, the status of the two branches to be merged '''must''' be the _exactly_ the same before starting to merge. | 
          
            |  | 45 | In this case, we can imagine we want to merge `feature_X' into `master': | 
          
            |  | 46 |  | 
          
            |  | 47 | {{{ | 
          
            |  | 48 | o-------A-------B  master | 
          
            |  | 49 | \ | 
          
            |  | 50 | D-------E  feature_X | 
          
            |  | 51 | }}} | 
          
            |  | 52 |  | 
          
            |  | 53 | Going to the terminal, this means: | 
          
            |  | 54 |  | 
          
            |  | 55 | {{{ | 
          
            |  | 56 | #!sh | 
          
            |  | 57 | $ git fetch origin | 
          
            |  | 58 | $ # already up-to-date? otherwise pull new changes on both branches | 
          
            |  | 59 | $ | 
          
            |  | 60 | $ git branch | 
          
            |  | 61 | feature_X | 
          
            |  | 62 | * master | 
          
            |  | 63 | release_8.4 | 
          
            |  | 64 | release_8.5 | 
          
            |  | 65 | $ git merge feature_X --no-ff | 
          
            |  | 66 | $ # In case of "Automatic merge failed; fix conflicts and then commit the result.", then see you later. | 
          
            |  | 67 | $ # otherwise: | 
          
            |  | 68 | $ git log --oneline -1 master | 
          
            |  | 69 | 3f36d7f Merge branch 'feature_X' into master | 
          
            |  | 70 | }}} | 
          
            |  | 71 |  | 
          
            |  | 72 | After the merge, the situation (locally) is then: | 
          
            |  | 73 |  | 
          
            |  | 74 | {{{ | 
          
            |  | 75 | o-------A--------------M  master | 
          
            |  | 76 | \            / | 
          
            |  | 77 | C----------D  feature_X | 
          
            |  | 78 | }}} | 
          
            |  | 79 |  | 
          
            |  | 80 | To publish this on the public repo you can create the bundle, but first (again) remember that: | 
          
            |  | 81 |  | 
          
            |  | 82 | * local snapshot of two branches must ''exactly'' be synchronized with that of the public repo | 
          
            |  | 83 | * consequently, the ''names'' of the merging branches must be the same (as developers tend to open branches for local development..) | 
          
            |  | 84 |  | 
          
            |  | 85 | If it is all fine, create the bundle: | 
          
            |  | 86 |  | 
          
            |  | 87 | * Synopsis: | 
          
            |  | 88 | {{{ | 
          
            |  | 89 | #!sh | 
          
            |  | 90 | $ git bundle create <bundle_name> <branch_name> <refs> | 
          
            |  | 91 | }}} | 
          
            |  | 92 | * Example: | 
          
            |  | 93 | {{{ | 
          
            |  | 94 | #!sh | 
          
            |  | 95 | # A graph view first: | 
          
            |  | 96 | $ git log master --graph -4 | 
          
            |  | 97 | *   commit 3f36d7f1a19c3e4cfeab66807dd39f6d7fda771b | 
          
            |  | 98 | |\  Merge: 5ee465b f7ed86b | 
          
            |  | 99 | | | Author: Willie The Merger <w.merger@jacobs-university.de> | 
          
            |  | 100 | | | Date:   Tue Oct 15 12:37:53 2013 +0200 | 
          
            |  | 101 | | | | 
          
            |  | 102 | | |     Merge branch 'feature_X' into master | 
          
            |  | 103 | | | | 
          
            |  | 104 | | * commit f7ed86b6eba15e141202b44279d7f7afa4484944 | 
          
            |  | 105 | | | Author: Jack Shortie <j.shortie@jacobs-university.de> | 
          
            |  | 106 | | | Date:   Tue Oct 8 12:34:54 2013 +0200 | 
          
            |  | 107 | | | | 
          
            |  | 108 | | |     D | 
          
            |  | 109 | | | | 
          
            |  | 110 | | * commit 79e8805fe4b4ba2502be9c0e4b312b8b97e739b9 | 
          
            |  | 111 | |/  Author: Johnnie Cannuccia <j.cnnuccia@acme.org> | 
          
            |  | 112 | |   Date:   Tue Oct 8 12:21:58 2013 +0200 | 
          
            |  | 113 | | | 
          
            |  | 114 | |       C | 
          
            |  | 115 | | | 
          
            |  | 116 | * commit 5ee465b1ca5306590dce61e97acb97f1e88aa3c1 | 
          
            |  | 117 | | Author: Piero Campalani <p.campalani@jacobs-university.de> | 
          
            |  | 118 | | Date:   Thu Aug 8 14:24:32 2013 +0200 | 
          
            |  | 119 | | | 
          
            |  | 120 | |     A | 
          
            |  | 121 |  | 
          
            |  | 122 |  | 
          
            |  | 123 | $ # Verify which HEADs will go into the bundle | 
          
            |  | 124 | $ git log master ^5ee465 --oneline | 
          
            |  | 125 | 3f36d7f Merge branch 'ProvaMerge' into ProvaMergeMaster | 
          
            |  | 126 | f7ed86b D | 
          
            |  | 127 | 79e8805 C | 
          
            |  | 128 |  | 
          
            |  | 129 | $ # Create the bundle | 
          
            |  | 130 | $ git bundle create ticket:XYZ_MergingFeature_xOnMaster.bundle master ^5ee465 | 
          
            |  | 131 | Counting objects: 14, done. | 
          
            |  | 132 | Delta compression using up to 2 threads. | 
          
            |  | 133 | Compressing objects: 100% (9/9), done. | 
          
            |  | 134 | Writing objects: 100% (9/9), 838 bytes, done. | 
          
            |  | 135 | Total 9 (delta 8), reused 0 (delta 0) | 
          
            |  | 136 |  | 
          
            |  | 137 | $ # See inside it: | 
          
            |  | 138 | $ git list-heads ticket:XYZ_MergingFeature_xOnMaster.bundle | 
          
            |  | 139 | 3f36d7f1a19c3e4cfeab66807dd39f6d7fda771b refs/heads/master | 
          
            |  | 140 | }}} | 
          
            |  | 141 |  | 
          
            |  | 142 | == Verifying the bundle == | 
          
            |  | 143 |  | 
          
            |  | 144 | In case you need to locally verify that you produced a good bundle, you can create a new local repo and test it: | 
          
            |  | 145 |  | 
          
            |  | 146 | {{{ | 
          
            |  | 147 | #!sh | 
          
            |  | 148 | $ # Create/init new empty repo | 
          
            |  | 149 | $ echo `pwd` | 
          
            |  | 150 | /home/rasdaman/rasdaman | 
          
            |  | 151 | $ mkdir ~/test_repo | 
          
            |  | 152 | $ cd ~/test_repo | 
          
            |  | 153 | $ git init | 
          
            |  | 154 | $ cd /home/rasdaman/rasdaman | 
          
            |  | 155 | $ git remote add test_remote ~/test_repo/ | 
          
            |  | 156 | $ # push two branches to the test repo | 
          
            |  | 157 | $ git push test_remote master | 
          
            |  | 158 | $ git push test_remote feature_X | 
          
            |  | 159 | $ # Now move to the test repo and apply the bundle (1-verify, 2-apply) | 
          
            |  | 160 | $ cd ~/test_repo | 
          
            |  | 161 | $ git branch | 
          
            |  | 162 | feature_X | 
          
            |  | 163 | * master | 
          
            |  | 164 | $ # check out on a branch you're not merging into: | 
          
            |  | 165 | $ git checkout feature_x | 
          
            |  | 166 | $ git branch | 
          
            |  | 167 | * feature_X | 
          
            |  | 168 | master | 
          
            |  | 169 | $ git bundle verify /path/to/ticket:XYZ_MergingFeature_xOnMaster.bundle | 
          
            |  | 170 | $ git fetch /path/to/ticket:XYZ_MergingFeature_xOnMaster.bundle master:master | 
          
            |  | 171 | }}} | 
          
            |  | 172 |  | 
          
            |  | 173 |  | 
          
            |  | 174 | == Further reading == | 
          
            |  | 175 |  | 
          
            |  | 176 | * [http://git-scm.com/2010/03/10/bundles.html Git's Little Bundle of Joy] | 
          
            |  | 177 | * [http://stackoverflow.com/questions/3635952/how-to-use-git-bundle-for-keeping-development-in-sync How to use git-bundle for keeping development in sync] | 
          
            |  | 178 | * [http://stackoverflow.com/questions/2285699/git-how-to-create-patches-for-a-merge Git: How to create patches for a merge?] |