From d2bf9e8c6343acdb3791072f79235f94789a6d3b Mon Sep 17 00:00:00 2001 From: Steve Binkowski Date: Wed, 28 Sep 2016 12:37:48 -0400 Subject: [PATCH] Find common ancestor of two branches --- README.md | 6 ++++++ tips.json | 3 +++ 2 files changed, 9 insertions(+) diff --git a/README.md b/README.md index 08fea5b..171d9a0 100644 --- a/README.md +++ b/README.md @@ -142,6 +142,7 @@ P.S: All these commands are tested on `git version 2.7.4 (Apple Git-66)`. * [Add object notes](#add-object-notes) * [Show all the git-notes](#show-all-the-git-notes) * [Apply commit from another repository](#apply-commit-from-another-repository) +* [Find common ancestor of two branches](#find-common-ancestor-of-two-branches) @@ -960,5 +961,10 @@ git log --show-notes='*' git --git-dir=/.git format-patch -k -1 --stdout | git am -3 -k ``` +## Find common ancestor of two branches +```sh +diff -u <(git rev-list --first-parent BranchA) <(git rev-list --first-parent BranchB) | sed -ne 's/^ //p' | head -1 +``` + diff --git a/tips.json b/tips.json index 89e877a..781e03a 100644 --- a/tips.json +++ b/tips.json @@ -414,4 +414,7 @@ }, { "title": "Apply commit from another repository", "tip": "git --git-dir=/.git format-patch -k -1 --stdout | git am -3 -k" +}, { + "title": "Find common ancestor of two branches", + "tip": "diff -u <(git rev-list --first-parent BranchA) <(git rev-list --first-parent BranchB) | sed -ne 's/^ //p' | head -1" }]