Forrest logo
back to the git tool

git-merge-base:tldr:8bba6

git-merge-base: Check if a commit is an ancestor of a specific commit.
$ git merge-base --is-ancestor ${ancestor_commit} ${commit}
try on your machine

The git merge-base --is-ancestor command is used to check whether one commit is an ancestor of another commit in a Git repository.

Here's the breakdown of the command:

  • git merge-base is a Git command that finds the common ancestor(s) between two commits.
  • --is-ancestor is an option used with git merge-base to determine if one commit is an ancestor of another.
  • ${ancestor_commit} is a placeholder that should be replaced with the commit hash or reference of the supposed ancestor commit.
  • ${commit} is a placeholder that should be replaced with the commit hash or reference of the commit that is being checked if it is an ancestor.

By running this command, Git will determine if ${ancestor_commit} is an ancestor of ${commit}. If ${ancestor_commit} is indeed an ancestor, the command will exit with a return code of 0. If not, the return code will be non-zero.

This command is commonly used in scripts or conditional statements to check the relationship between commits before performing certain actions, such as merging or rebasing.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the git tool