Ron
Ron

Reputation: 23526

Get latest commit in branch x which is also in branch y

I am looking for a CLI command to achieve the following:

Get latest commit in branch x which is also in branch y

I googled around and found this:

git diff -u <(git rev-list --first-parent origin/feature/x) <(git rev-list --first-parent origin/feature/y) | sed -ne 's/^ //p' | head -1

Unfortunately, this doesn't work on my server on an alpine image and it seems super complicated. That's why I'm looking for a new solution.

Thx!

Upvotes: 3

Views: 55

Answers (1)

Romain Valeri
Romain Valeri

Reputation: 22057

You might want to use

git merge-base <commit-ish> <commit-ish> (doc for git merge-base)

which outputs the hash of the most recent common ancestor.

Note that <commit-ish> here can be a commit hash as well as a branch name, see the definition here.

Upvotes: 5

Related Questions