Linux command
git-merge-base 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Find the best common ancestor
git merge-base [branch1] [branch2]
Find all common ancestors
git merge-base --all [branch1] [branch2]
Check if a commit is an ancestor
git merge-base --is-ancestor [commit1] [commit2]
Find the fork point
git merge-base --fork-point [upstream_ref] [branch]
Find octopus merge base
git merge-base --octopus [branch1] [branch2] [branch3]
List independent commits
git merge-base --independent [commit1] [commit2] [commit3]
说明
git merge-base finds the best common ancestor(s) between two commits to use in a three-way merge. A common ancestor is "best" if it is not an ancestor of any other common ancestor. One common ancestor that is an ancestor of all best common ancestors is a "merge base". The `--fork-point` option finds where a branch diverged from an upstream branch, taking the reflog into account to handle history rewrites (e.g., after upstream rebase). The `--is-ancestor` option checks if one commit is an ancestor of another, which is useful in scripts for determining commit relationships. The `--independent` option filters a set of commits to only those not reachable from others. For octopus merges (merging more than two branches), the `--octopus` option computes a common base for multiple commits simultaneously.
参数
- -a, --all
- Output all merge bases for the commits, instead of just one.
- --octopus
- Compute the best common ancestors of all supplied commits, in preparation for an n-way merge.
- --independent
- Instead of printing merge bases, print a minimal subset of the supplied commits with the same ancestors. Lists commits which cannot be reached from any other.
- --is-ancestor
- Check if the first commit is an ancestor of the second. Exits with status 0 if true, status 1 if not. Errors are signaled by a non-zero status that is not 1.
- --fork-point
- Find the point at which a branch forked from another reference. Takes into account the reflog of the reference to detect forks from earlier incarnations of the branch (useful after history rewrites).
FAQ
What is the git-merge-base command used for?
git merge-base finds the best common ancestor(s) between two commits to use in a three-way merge. A common ancestor is "best" if it is not an ancestor of any other common ancestor. One common ancestor that is an ancestor of all best common ancestors is a "merge base". The `--fork-point` option finds where a branch diverged from an upstream branch, taking the reflog into account to handle history rewrites (e.g., after upstream rebase). The `--is-ancestor` option checks if one commit is an ancestor of another, which is useful in scripts for determining commit relationships. The `--independent` option filters a set of commits to only those not reachable from others. For octopus merges (merging more than two branches), the `--octopus` option computes a common base for multiple commits simultaneously.
How do I run a basic git-merge-base example?
Run `git merge-base [branch1] [branch2]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -a, --all do in git-merge-base?
Output all merge bases for the commits, instead of just one.