Skip to content

Instantly share code, notes, and snippets.

@briceburg
Created November 22, 2015 05:42
Show Gist options
  • Save briceburg/3f41f09bdc478d21bcf8 to your computer and use it in GitHub Desktop.
Save briceburg/3f41f09bdc478d21bcf8 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.
@it3xl
Copy link

it3xl commented Nov 25, 2017

Just brilliant! And google friendly. Appreciative.

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