Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Alternate solution to the one presented by <a href="https://stackoverflow.com/questions/1467200/how-to-merge-remote-master-at-two-commits-earlier-than-current-local-master/1467303#1467303">VonC</a> would be to use "ours" merge strategy to join histories, but to take one version:</p> <pre><code>$ git checkout -b tmp original-repo/master $ git merge -s ours master # take version from 'tmp', i.e. from 'original-repo/master' $ git checkout master $ git merge tmp # should be fast forward $ git branch -d tmp # 'tmp' branch is no longer needed </code></pre> <p>What you do above is to do in short "theirs" merge.</p> <p><strong>Caveat:</strong> <em>this solution solves original problem <strong>only</strong> if there are no other commits on local branch since last merge (last update), that the ones which are to be replaced by version from original repository!!!</em></p> <p><em>So this solution allows to keep your version of solving the problem for the history, but is more limited in application.</em></p> <hr> <p>Below there is set of ASCII-art diagrams showing what is happening in the repository in each step:</p> <ol> <li>before first command: <pre> \*---\*---x---A &lt;-- original-repo/master (remote-tracking branch) \ \\--a---b &lt;-- master &lt;-- HEAD </pre></li> <li>after "<code>git checkout -b tmp original-repo/master</code>": <pre> &lt;-- original-repo/master, *---*---x---A &lt;-- tmp &lt;-- HEAD \ \--a---b &lt;-- master </pre> where both 'tmp' (local branch) and 'original-repo/master' (remote-tracking branch) point to the same commit.</li> <li>after "<code>git merge -s ours master</code>": <pre> /-------------- original-repo/master v *---*---x---A----A' &lt;-- tmp &lt;-- HEAD \ / \--a---b &lt;-- master </pre> where commit A' is a merge commit, but has the same contents (the same tree) as commit A</li> <li>after "<code>git checkout master &amp;&amp; git merge tmp</code>" (the merge should be fast-forward): <pre> /-------------- original-repo/master v *---*---x---A----A' &lt;-- tmp, \ / &lt;-- master &lt;-- HEAD \--a---b </pre> Both 'master' and 'tmp' point to the same commit.</li> <li>after "<code>git branch -d tmp</code>", and some reorganizing of the diagram <pre> \*---\*---x---A-----\ &lt;-- original-repo/master \ \ \\--a---b---A' &lt;-- master &lt;-- HEAD </pre></li> </ol> <p>At the end:</p> <ul> <li>remote-tracking branch '<code>original-repo/master</code>' (i.e. '<code>refs/remotes/original-repo/master</code>') points to commit A, </li> <li>local branch '<code>master</code>' (i.e. '<code>refs/heads/master</code>'), which is current branch, points to commit A'.<br> Commit A' has: <ul> <li>commit A as its first parent (<code>A'^1 == A</code>), </li> <li>commit b as second parent (<code>A'^2 == a</code>), </li> <li>and its contents (its tree) is the same as in commit A (<code>A'^{tree} == A^{tree}</code>).</li> </ul></li> </ul>
    singulars
    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.
    1. VO
      singulars
      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