git-merge-base.1   [plain text]


'\" t
.\"     Title: git-merge-base
.\"    Author: [FIXME: author] [see http://docbook.sf.net/el/author]
.\" Generator: DocBook XSL Stylesheets v1.75.2 <http://docbook.sf.net/>
.\"      Date: 06/01/2011
.\"    Manual: Git Manual
.\"    Source: Git 1.7.5.4
.\"  Language: English
.\"
.TH "GIT\-MERGE\-BASE" "1" "06/01/2011" "Git 1\&.7\&.5\&.4" "Git Manual"
.\" -----------------------------------------------------------------
.\" * set default formatting
.\" -----------------------------------------------------------------
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.\" -----------------------------------------------------------------
.\" * MAIN CONTENT STARTS HERE *
.\" -----------------------------------------------------------------
.SH "NAME"
git-merge-base \- Find as good common ancestors as possible for a merge
.SH "SYNOPSIS"
.sp
.nf
\fIgit merge\-base\fR [\-a|\-\-all] <commit> <commit>\&...
\fIgit merge\-base\fR [\-a|\-\-all] \-\-octopus <commit>\&...
\fIgit merge\-base\fR \-\-independent <commit>\&...
.fi
.sp
.SH "DESCRIPTION"
.sp
\fIgit merge\-base\fR finds best common ancestor(s) between two commits to use in a three\-way merge\&. One common ancestor is \fIbetter\fR than another common ancestor if the latter is an ancestor of the former\&. A common ancestor that does not have any better common ancestor is a \fIbest common ancestor\fR, i\&.e\&. a \fImerge base\fR\&. Note that there can be more than one merge base for a pair of commits\&.
.SH "OPERATION MODE"
.sp
As the most common special case, specifying only two commits on the command line means computing the merge base between the given two commits\&.
.sp
More generally, among the two commits to compute the merge base from, one is specified by the first commit argument on the command line; the other commit is a (possibly hypothetical) commit that is a merge across all the remaining commits on the command line\&.
.sp
As a consequence, the \fImerge base\fR is not necessarily contained in each of the commit arguments if more than two commits are specified\&. This is different from \fBgit-show-branch\fR(1) when used with the \-\-merge\-base option\&.
.PP
\-\-octopus
.RS 4
Compute the best common ancestors of all supplied commits, in preparation for an n\-way merge\&. This mimics the behavior of
\fIgit show\-branch \-\-merge\-base\fR\&.
.RE
.PP
\-\-independent
.RS 4
Instead of printing merge bases, print a minimal subset of the supplied commits with the same ancestors\&. In other words, among the commits given, list those which cannot be reached from any other\&. This mimics the behavior of
\fIgit show\-branch \-\-independent\fR\&.
.RE
.SH "OPTIONS"
.PP
\-a, \-\-all
.RS 4
Output all merge bases for the commits, instead of just one\&.
.RE
.SH "DISCUSSION"
.sp
Given two commits \fIA\fR and \fIB\fR, git merge\-base A B will output a commit which is reachable from both \fIA\fR and \fIB\fR through the parent relationship\&.
.sp
For example, with this topology:
.sp
.if n \{\
.RS 4
.\}
.nf
         o\-\-\-o\-\-\-o\-\-\-B
        /
\-\-\-o\-\-\-1\-\-\-o\-\-\-o\-\-\-o\-\-\-A
.fi
.if n \{\
.RE
.\}
.sp
the merge base between \fIA\fR and \fIB\fR is \fI1\fR\&.
.sp
Given three commits \fIA\fR, \fIB\fR and \fIC\fR, git merge\-base A B C will compute the merge base between \fIA\fR and a hypothetical commit \fIM\fR, which is a merge between \fIB\fR and \fIC\fR\&. For example, with this topology:
.sp
.if n \{\
.RS 4
.\}
.nf
       o\-\-\-o\-\-\-o\-\-\-o\-\-\-C
      /
     /   o\-\-\-o\-\-\-o\-\-\-B
    /   /
\-\-\-2\-\-\-1\-\-\-o\-\-\-o\-\-\-o\-\-\-A
.fi
.if n \{\
.RE
.\}
.sp
the result of git merge\-base A B C is \fI1\fR\&. This is because the equivalent topology with a merge commit \fIM\fR between \fIB\fR and \fIC\fR is:
.sp
.if n \{\
.RS 4
.\}
.nf
       o\-\-\-o\-\-\-o\-\-\-o\-\-\-o
      /                 \e
     /   o\-\-\-o\-\-\-o\-\-\-o\-\-\-M
    /   /
\-\-\-2\-\-\-1\-\-\-o\-\-\-o\-\-\-o\-\-\-A
.fi
.if n \{\
.RE
.\}
.sp
and the result of git merge\-base A M is \fI1\fR\&. Commit \fI2\fR is also a common ancestor between \fIA\fR and \fIM\fR, but \fI1\fR is a better common ancestor, because \fI2\fR is an ancestor of \fI1\fR\&. Hence, \fI2\fR is not a merge base\&.
.sp
The result of git merge\-base \-\-octopus A B C is \fI2\fR, because \fI2\fR is the best common ancestor of all commits\&.
.sp
When the history involves criss\-cross merges, there can be more than one \fIbest\fR common ancestor for two commits\&. For example, with this topology:
.sp
.if n \{\
.RS 4
.\}
.nf
\-\-\-1\-\-\-o\-\-\-A
    \e /
     X
    / \e
\-\-\-2\-\-\-o\-\-\-o\-\-\-B
.fi
.if n \{\
.RE
.\}
.sp
both \fI1\fR and \fI2\fR are merge\-bases of A and B\&. Neither one is better than the other (both are \fIbest\fR merge bases)\&. When the \-\-all option is not given, it is unspecified which best one is output\&.
.SH "SEE ALSO"
.sp
\fBgit-rev-list\fR(1), \fBgit-show-branch\fR(1), \fBgit-merge\fR(1)
.SH "GIT"
.sp
Part of the \fBgit\fR(1) suite