Reputation: 862
I have some customer branches and one development branch. Every now and then the customer branches are merged back into the development branch. For an Update, the development branch is merged into the customer branch which got the Update.
Now I want to find out, What was the last update-merge, or what was the last merge between the development and the customer branch.
If I have for example the following history:
o---o---o---o---o---o c1
/ \
o---1---o---2---o---o---3---o dev
\ / \ / /
o---o---o---o---o---o c2
In this example, I want to find the last merge from dev
to c2
which is 2.
I found git merge-base
from this answer, but this gives me 3 as it is the last commit which is in both branches.
I also tryed to look at the commits, which are in dev
but not in c2
, but then I also got a lot of old commits from c1
.
Upvotes: 3
Views: 153
Reputation: 52151
Commit 2
is the most recent commit which is both :
first-parent
ancestor of branch dev
c2
You can spot it by combining git commands with grep and head :
# two lines and a temp file :
# 1. list the hashes of 'first-parent' commits from branch 'dev' :
git rev-list --first-parent dev > /tmp/dev.log.txt
# 2. in the parents of branch 'c2', look for the first line which matches a
# first-parent of 'dev'
git rev-list c2 | grep -f /tmp/dev.log.txt | head -1
# one liner ('<(...)' works in bash and zsh) :
git rev-list c2 | grep -f <(git rev-list --first-parent dev) | head -1
Upvotes: 4