Changes between Version 22 and Version 23 of GitForDarcsUsers


Ignore:
Timestamp:
Aug 15, 2008 10:33:26 AM (6 years ago)
Author:
nominolo
Comment:

Talk about git rebase

Legend:

Unmodified
Added
Removed
Modified
  • GitForDarcsUsers

    v22 v23  
    4141o---o---A---o---o---o <-- master 
    4242}}} 
    43 This merge is actually a '''fast-forward''', meaning that no new commit is necessary, since "develop" didn't contain any other changes the pointer for the "develop" branch is merely set to point to the same commit that feature1 pointed to.  On the other hand, if we now merge "devel" into "master" we get a now commit: 
     43The above merge is actually a '''fast-forward''', meaning that no new commit is necessary, since "develop" didn't contain any other changes--the pointer for the "develop" branch is merely set to point to the same commit that feature1 pointed to.  On the other hand, if we now merge "devel" into "master" we get a now commit: 
    4444{{{ 
    4545$ git checkout master 
     
    5858First of all, {{{git rebase}}} is a very dangerous feature, ''it should never be done in shared repositories'' (this is like {{{darcs amend-record}}} and {{{darcs unpull}}}, but even harder to fix.) 
    5959 
    60 {{{git rebase}}} is a way to "rewrite history".  (XXX: complete me) 
     60{{{git rebase}}} is a way to "rewrite history".  You can use this to remove bad patches or to move a branch. For example, consider the following history: 
     61{{{ 
     62      A---B---C---D <-- feature1 
     63; 
     64o---o---o---o---o <-- master 
     65}}} 
     66Now, it turns out that {{{B}}} was not a good patch.  With {{{git rebase}}}, you can choose to just remove {{{B}}} completely (similar to {{{darcs unpull}}}) 
     67{{{ 
     68      A---C'---D' <-- feature1 
     69; 
     70o---o---o---o---o <-- master 
     71}}} 
     72or you could edit {{{B}}} and replace it with another change {{{B'}}} (similar to {{{darcs amend-record}}}). 
     73{{{ 
     74      A---B'---C'---D' <-- feature1 
     75; 
     76o---o---o---o---o <-- master 
     77}}} 
     78The easiest way is to use {{{rebase}}} for these use cases is via {{{git rebase -i}}} (see its documentation). 
     79 
     80Note in the above examples how patches {{{C}}} and {{{D}}} got renamed to {{{C'}}}, {{{D'}}}.  This indicates that they now have different commit ids because they are now are the same patches but based upon a different history.  That means that another user that already has the original patches {{{C}}} and {{{D}}} and tries to update from the rebased branch will get conflicts!  (This is comparable to how an amended patch in darcs will lead to conflicts, if someone else already has the original patch in the repository.) 
     81 
     82Therefore: '''Never rebase a published branch'''. 
     83 
     84Another use case is to move a branch.  In the above example we can rebase {{{feature1}}} onto {{{master}}}, resulting in this history: 
     85{{{ 
     86                  A'---B'---C'---D' <-- feature1 
     87; 
     88o---o---o---o---o <-- master 
     89}}} 
     90You can do this if the changes in the feature branch semantically aren't really a branch, but make equally sense on top of the master's history.  In the above example, merging {{{feature1}}} into {{{master}}} will now be a simple fast-forward and will not introduce a merge commit. 
     91 
     92Finally, {{{rebase}}} can be used to move a feature branch onto another branch.  For example, say we have a big feature and we want to implement a smaller feature: 
     93{{{ 
     94                o---o---o <-- small_feature 
     95; 
     96          o---o <-- big_feature   
     97; 
     98o---o---A---o---o---o <-- master 
     99}}} 
     100Now we realise that {{{small_feature}}} is already useful and want to merge it into master without the commits that were made on the {{{big_feature}}} branch.  We can therefore rebase {{{small_feature}}} onto master: 
     101{{{ 
     102$ git rebase --onto master big_feature small_feature 
     103          o---o <-- big_feature 
     104; 
     105        |             o'--o'--o' <-- small_feature 
     106        |            /  
     107o---o---A---o---o---o <-- master 
     108}}} 
     109 
     110See {{{git rebase --help}}} for more usage information and more examples. 
    61111 
    62112= General Settings =