summaryrefslogtreecommitdiffstats
path: root/git-merge-base.html
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2017-11-27 12:33:28 +0900
committerJunio C Hamano <gitster@pobox.com>2017-11-27 12:33:28 +0900
commit4886c778b44a0a4b9eb64392c58bf4ff20b4f587 (patch)
tree08814376b93eb76988551e85a5a30a5e460c8adc /git-merge-base.html
parentd71056015c147557a3bbf069107d9470c0579974 (diff)
downloadgit-htmldocs-4886c778b44a0a4b9eb64392c58bf4ff20b4f587.tar.gz
Autogenerated HTML docs for v2.15.0-374-g5f995
Diffstat (limited to 'git-merge-base.html')
-rw-r--r--git-merge-base.html67
1 files changed, 56 insertions, 11 deletions
diff --git a/git-merge-base.html b/git-merge-base.html
index 07001c3a6..503b84ea6 100644
--- a/git-merge-base.html
+++ b/git-merge-base.html
@@ -932,24 +932,69 @@ topic origin/master</code>, the history of remote-tracking branch
history of this shape:</p></div>
<div class="literalblock">
<div class="content">
-<pre><code> o---B1
+<pre><code> o---B2
/
----o---o---B2--o---o---o---B (origin/master)
+---o---o---B1--o---o---o---B (origin/master)
\
- B3
+ B0
\
- Derived (topic)</code></pre>
+ D0---D1---D (topic)</code></pre>
</div></div>
-<div class="paragraph"><p>where <code>origin/master</code> used to point at commits B3, B2, B1 and now it
+<div class="paragraph"><p>where <code>origin/master</code> used to point at commits B0, B1, B2 and now it
points at B, and your <code>topic</code> branch was started on top of it back
-when <code>origin/master</code> was at B3. This mode uses the reflog of
-<code>origin/master</code> to find B3 as the fork point, so that the <code>topic</code>
-can be rebased on top of the updated <code>origin/master</code> by:</p></div>
+when <code>origin/master</code> was at B0, and you built three commits, D0, D1,
+and D, on top of it. Imagine that you now want to rebase the work
+you did on the topic on top of the updated origin/master.</p></div>
+<div class="paragraph"><p>In such a case, <code>git merge-base origin/master topic</code> would return the
+parent of B0 in the above picture, but B0^..D is <strong>not</strong> the range of
+commits you would want to replay on top of B (it includes B0, which
+is not what you wrote; it is a commit the other side discarded when
+it moved its tip from B0 to B1).</p></div>
+<div class="paragraph"><p><code>git merge-base --fork-point origin/master topic</code> is designed to
+help in such a case. It takes not only B but also B0, B1, and B2
+(i.e. old tips of the remote-tracking branches your repository&#8217;s
+reflog knows about) into account to see on which commit your topic
+branch was built and finds B0, allowing you to replay only the
+commits on your topic, excluding the commits the other side later
+discarded.</p></div>
+<div class="paragraph"><p>Hence</p></div>
<div class="literalblock">
<div class="content">
-<pre><code>$ fork_point=$(git merge-base --fork-point origin/master topic)
-$ git rebase --onto origin/master $fork_point topic</code></pre>
+<pre><code>$ fork_point=$(git merge-base --fork-point origin/master topic)</code></pre>
</div></div>
+<div class="paragraph"><p>will find B0, and</p></div>
+<div class="literalblock">
+<div class="content">
+<pre><code>$ git rebase --onto origin/master $fork_point topic</code></pre>
+</div></div>
+<div class="paragraph"><p>will replay D0, D1 and D on top of B to create a new history of this
+shape:</p></div>
+<div class="literalblock">
+<div class="content">
+<pre><code> o---B2
+ /
+---o---o---B1--o---o---o---B (origin/master)
+ \ \
+ B0 D0'--D1'--D' (topic - updated)
+ \
+ D0---D1---D (topic - old)</code></pre>
+</div></div>
+<div class="paragraph"><p>A caveat is that older reflog entries in your repository may be
+expired by <code>git gc</code>. If B0 no longer appears in the reflog of the
+remote-tracking branch <code>origin/master</code>, the <code>--fork-point</code> mode
+obviously cannot find it and fails, avoiding to give a random and
+useless result (such as the parent of B0, like the same command
+without the <code>--fork-point</code> option gives).</p></div>
+<div class="paragraph"><p>Also, the remote-tracking branch you use the <code>--fork-point</code> mode
+with must be the one your topic forked from its tip. If you forked
+from an older commit than the tip, this mode would not find the fork
+point (imagine in the above sample history B0 did not exist,
+origin/master started at B1, moved to B2 and then B, and you forked
+your topic at origin/master^ when origin/master was B1; the shape of
+the history would be the same as above, without B0, and the parent
+of B1 is what <code>git merge-base origin/master topic</code> correctly finds,
+but the <code>--fork-point</code> mode will not, because it is not one of the
+commits that used to be at the tip of origin/master).</p></div>
</div>
</div>
<div class="sect1">
@@ -970,7 +1015,7 @@ $ git rebase --onto origin/master $fork_point topic</code></pre>
<div id="footnotes"><hr /></div>
<div id="footer">
<div id="footer-text">
-Last updated 2016-10-27 07:23:54 JST
+Last updated 2017-11-27 12:32:50 JST
</div>
</div>
</body>