Skip to content

Instantly share code, notes, and snippets.

@jdforsythe
Created August 2, 2016 12:29
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jdforsythe/e74a766b438ca234fb7e4593e056b384 to your computer and use it in GitHub Desktop.
Save jdforsythe/e74a766b438ca234fb7e4593e056b384 to your computer and use it in GitHub Desktop.
GIT find commit where branched off
#!/bin/bash
# "master" is the name of your main branch you'll be comparing to, or you can pass the "parent" branch as an argument
# it compares against the current branch by default, but you can pass a second argument to specify a child branch
# this creates a permanent alias so you can use `git oldest-ancestor` to get the oldest ancestor of the current branch at any time
git config --global alias.oldest-ancestor '!zsh -c '\''diff --old-line-format='' --new-line-format='' <(git rev-list --first-parent "${1:-master}") <(git rev-list --first-parent "${2:-HEAD}") | head -1'\'' -'
#!/bin/bash
# $1 is the main ancestor branch to compare to (defaults to `master`)
# $2 is the child branch to find the ancestor of (defaults to current branch)
diff --old-line-format='' --new-line-format='' <(git rev-list --first-parent "${1:-master}") <(git rev-list --first-parent "${2:-HEAD}") | head -1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment