updated git doc
[TortoiseGit.git] / doc / source / en / TortoiseGit / git_doc / git-merge-base.xml
blob902004223d89133d9cc7911dda027856c7ee4610
1 <?xml version="1.0" encoding="UTF-8"?>\r
2 <!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">\r
3 \r
4 <article lang="en" id="git-merge-base(1)">\r
5 <articleinfo>\r
6     <title>git-merge-base(1)</title>\r
7 <indexterm>\r
8 <primary>git-merge-base(1)</primary>\r
9 </indexterm>\r
10 </articleinfo>\r
11 <simplesect id="_name">\r
12 <title>NAME</title>\r
13 <simpara>git-merge-base - Find as good common ancestors as possible for a merge</simpara>\r
14 </simplesect>\r
15 <simplesect id="_synopsis">\r
16 <title>SYNOPSIS</title>\r
17 <blockquote>\r
18 <literallayout><emphasis>git merge-base</emphasis> [-a|--all] &lt;commit&gt; &lt;commit&gt;&#8230;\r
19 <emphasis>git merge-base</emphasis> [-a|--all] --octopus &lt;commit&gt;&#8230;\r
20 <emphasis>git merge-base</emphasis> --independent &lt;commit&gt;&#8230;</literallayout>\r
21 </blockquote>\r
22 </simplesect>\r
23 <simplesect id="_description">\r
24 <title>DESCRIPTION</title>\r
25 <simpara><emphasis>git merge-base</emphasis> finds best common ancestor(s) between two commits to use\r
26 in a three-way merge.  One common ancestor is <emphasis>better</emphasis> than another common\r
27 ancestor if the latter is an ancestor of the former.  A common ancestor\r
28 that does not have any better common ancestor is a <emphasis>best common\r
29 ancestor</emphasis>, i.e. a <emphasis>merge base</emphasis>.  Note that there can be more than one\r
30 merge base for a pair of commits.</simpara>\r
31 </simplesect>\r
32 <simplesect id="_operation_mode">\r
33 <title>OPERATION MODE</title>\r
34 <simpara>As the most common special case, specifying only two commits on the\r
35 command line means computing the merge base between the given two commits.</simpara>\r
36 <simpara>More generally, among the two commits to compute the merge base from,\r
37 one is specified by the first commit argument on the command line;\r
38 the other commit is a (possibly hypothetical) commit that is a merge\r
39 across all the remaining commits on the command line.</simpara>\r
40 <simpara>As a consequence, the <emphasis>merge base</emphasis> is not necessarily contained in each of the\r
41 commit arguments if more than two commits are specified. This is different\r
42 from <xref linkend="git-show-branch(1)" /> when used with the <emphasis>--merge-base</emphasis> option.</simpara>\r
43 <variablelist>\r
44 <varlistentry>\r
45 <term>\r
46 --octopus\r
47 </term>\r
48 <listitem>\r
49 <simpara>\r
50         Compute the best common ancestors of all supplied commits,\r
51         in preparation for an n-way merge.  This mimics the behavior\r
52         of <emphasis>git show-branch --merge-base</emphasis>.\r
53 </simpara>\r
54 </listitem>\r
55 </varlistentry>\r
56 <varlistentry>\r
57 <term>\r
58 --independent\r
59 </term>\r
60 <listitem>\r
61 <simpara>\r
62         Instead of printing merge bases, print a minimal subset of\r
63         the supplied commits with the same ancestors.  In other words,\r
64         among the commits given, list those which cannot be reached\r
65         from any other.  This mimics the behavior of <emphasis>git show-branch\r
66         --independent</emphasis>.\r
67 </simpara>\r
68 </listitem>\r
69 </varlistentry>\r
70 </variablelist>\r
71 </simplesect>\r
72 <simplesect id="_options">\r
73 <title>OPTIONS</title>\r
74 <variablelist>\r
75 <varlistentry>\r
76 <term>\r
77 -a\r
78 </term>\r
79 <term>\r
80 --all\r
81 </term>\r
82 <listitem>\r
83 <simpara>\r
84         Output all merge bases for the commits, instead of just one.\r
85 </simpara>\r
86 </listitem>\r
87 </varlistentry>\r
88 </variablelist>\r
89 </simplesect>\r
90 <simplesect id="_discussion">\r
91 <title>DISCUSSION</title>\r
92 <simpara>Given two commits <emphasis>A</emphasis> and <emphasis>B</emphasis>, <emphasis>git merge-base A B</emphasis> will output a commit\r
93 which is reachable from both <emphasis>A</emphasis> and <emphasis>B</emphasis> through the parent relationship.</simpara>\r
94 <simpara>For example, with this topology:</simpara>\r
95 <literallayout class="monospaced">         o---o---o---B\r
96         /\r
97 ---o---1---o---o---o---A</literallayout>\r
98 <simpara>the merge base between <emphasis>A</emphasis> and <emphasis>B</emphasis> is <emphasis>1</emphasis>.</simpara>\r
99 <simpara>Given three commits <emphasis>A</emphasis>, <emphasis>B</emphasis> and <emphasis>C</emphasis>, <emphasis>git merge-base A B C</emphasis> will compute the\r
100 merge base between <emphasis>A</emphasis> and a hypothetical commit <emphasis>M</emphasis>, which is a merge\r
101 between <emphasis>B</emphasis> and <emphasis>C</emphasis>.  For example, with this topology:</simpara>\r
102 <literallayout class="monospaced">       o---o---o---o---C\r
103       /\r
104      /   o---o---o---B\r
105     /   /\r
106 ---2---1---o---o---o---A</literallayout>\r
107 <simpara>the result of <emphasis>git merge-base A B C</emphasis> is <emphasis>1</emphasis>.  This is because the\r
108 equivalent topology with a merge commit <emphasis>M</emphasis> between <emphasis>B</emphasis> and <emphasis>C</emphasis> is:</simpara>\r
109 <literallayout class="monospaced">       o---o---o---o---o\r
110       /                 \\r
111      /   o---o---o---o---M\r
112     /   /\r
113 ---2---1---o---o---o---A</literallayout>\r
114 <simpara>and the result of <emphasis>git merge-base A M</emphasis> is <emphasis>1</emphasis>.  Commit <emphasis>2</emphasis> is also a\r
115 common ancestor between <emphasis>A</emphasis> and <emphasis>M</emphasis>, but <emphasis>1</emphasis> is a better common ancestor,\r
116 because <emphasis>2</emphasis> is an ancestor of <emphasis>1</emphasis>.  Hence, <emphasis>2</emphasis> is not a merge base.</simpara>\r
117 <simpara>The result of <emphasis>git merge-base --octopus A B C</emphasis> is <emphasis>2</emphasis>, because <emphasis>2</emphasis> is\r
118 the best common ancestor of all commits.</simpara>\r
119 <simpara>When the history involves criss-cross merges, there can be more than one\r
120 <emphasis>best</emphasis> common ancestor for two commits.  For example, with this topology:</simpara>\r
121 <literallayout class="monospaced">---1---o---A\r
122     \ /\r
123      X\r
124     / \\r
125 ---2---o---o---B</literallayout>\r
126 <simpara>both <emphasis>1</emphasis> and <emphasis>2</emphasis> are merge-bases of A and B.  Neither one is better than\r
127 the other (both are <emphasis>best</emphasis> merge bases).  When the <emphasis>--all</emphasis> option is not given,\r
128 it is unspecified which best one is output.</simpara>\r
129 </simplesect>\r
130 <simplesect id="_see_also">\r
131 <title>See also</title>\r
132 <simpara><xref linkend="git-rev-list(1)" />,\r
133 <xref linkend="git-show-branch(1)" />,\r
134 <xref linkend="git-merge(1)" /></simpara>\r
135 </simplesect>\r
136 <simplesect id="_git">\r
137 <title>GIT</title>\r
138 <simpara>Part of the <xref linkend="git(1)" /> suite</simpara>\r
139 </simplesect>\r
140 </article>\r