Skip to content

Instantly share code, notes, and snippets.

@tombruijn
Forked from jdforsythe/oldest-ancestor-alias.sh
Created October 3, 2021 18:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tombruijn/bc7fbdec8f704d057494cfbab475372e to your computer and use it in GitHub Desktop.
Save tombruijn/bc7fbdec8f704d057494cfbab475372e 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