Skip to content

Instantly share code, notes, and snippets.

@ejholmes
Forked from briceburg/git.md
Created August 31, 2018 01:27
Show Gist options
  • Save ejholmes/969fb9cb352564dc408875be0614d95b to your computer and use it in GitHub Desktop.
Save ejholmes/969fb9cb352564dc408875be0614d95b to your computer and use it in GitHub Desktop.
git - checking fast-forward-ness
git merge-base --is-ancestor master HEAD

from man git merge-base

A common idiom to check "fast-forward-ness" between two commits A and B is (or at least used to be) to compute the merge base between A and B, and check if it is the same as A, in which case, A is an ancestor of B. You will see this idiom used often in older scripts.

       A=$(git rev-parse --verify A)
       if test "$A" = "$(git merge-base A B)"
       then
               ... A is an ancestor of B ...
       fi

   In modern git, you can say this in a more direct way:

       if git merge-base --is-ancestor A B
       then
               ... A is an ancestor of B ...
       fi

   instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment