Note that there are some explanatory texts on larger screens.

plurals
  1. POgit rebase without merging any changes
    primarykey
    data
    text
    <p>Imagine we have two repositories in which the same piece of software is being developed. One being the legacy version that is shipped to customers, bugs are getting fixed and whatnot. And the other being the all so glorious rewrite of the same piece of software where everything that went wrong in A is now great and shiny (right…).</p> <p>So time goes by and at some point for whatever reason, we deem the rewrite a success. We decide to retire the legacy software. However we would like to keep it's history (just in case, you know…) while at the same time getting rid of the need for two repositories.</p> <p>Let's say Repository A looks like this:</p> <pre><code> A---B---C / \ D---E---F---G---H---I master (A) </code></pre> <p>And coincidentally Repository B looks like this:</p> <pre><code> S---R---Q / \ K---L---M---N---O---P master (B) </code></pre> <p>So, all we would love to do is type</p> <pre><code>[~/repo-a]$ git magic </code></pre> <p>and get this as a result:</p> <pre><code> A---B---C S---R---Q / \ / \ D---E---F---G---H---I---K---L---M---N---O---P master (A) </code></pre> <hr> <p>However sadly there is no <code>git-magic</code> command (that accomplishes what we want).</p> <p>What I tried so far was</p> <p>a] </p> <p>Looking at the man page of <code>git-rebase</code> the merge strategy <code>ours</code> seems to be what we wanted</p> <blockquote> <p>ours</p> <p>This resolves any number of heads, but the resulting tree of the merge is always that of the current branch head, effectively ignoring all changes from all other branches. It is meant to be used to supersede old development history of side branches. Note that this is different from the -Xours option to the recursive merge strategy.</p> </blockquote> <pre><code>[~/repo-a]$ git remote add shiny-rewrite git@github.com/orga/shiny-rewrite.git [~/repo-a]$ git fetch shiny-rewrite [~/repo-a]$ git checkout shiny-rewrite/master [~/repo-a]$ git checkout -b shiny-master [~/repo-a]$ git rebase -s ours master First, rewinding head to replay your work on top of it... Already applied: 0001 initial commit Already applied: 0002 blablabla Already applied: 0003 … Already applied: 0004 ZOMG IT'S READY All done. </code></pre> <p>However now all the commits from shiny-rewrite are gone. Not exactly what we wanted.</p> <p>b]</p> <p>The "brute-force" alternative</p> <pre><code>[~/repo-a]$ git rm -r * [~/repo-a]$ git commit -am "DELETE ALL THE THINGS" [~/repo-a]$ git remote add shiny-rewrite git@github.com/orga/shiny-rewrite.git [~/repo-a]$ git fetch shiny-rewrite [~/repo-a]$ git checkout shiny-rewrite/master [~/repo-a]$ git checkout -b shiny-master [~/repo-a]$ git rebase master [~/repo-a]$ git checkout master [~/repo-a]$ git merge shiny-master </code></pre> <p>But, now we have the this deletion commit..</p> <pre><code> A---B---C S---R---Q / \ / \ D---E---F---G---H---I---X---K---L---M---N---O---P master (A) /\ || "DELETE ALL THE THINGS" </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload