Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git commits on a specific branch

Tags:

git

I'm looking for the commits of a specific branch. My tree looks as follows:

feature/X     C--E--F
             /       \
master  -A--B--D---G--H--I--J->

How to get the commits C,E and F? What I tried is:

git rev-list feature/X ^master

but this gives no commits. I assume in that special case the problem is the back merge of feature/X to the master. That's why the commits C, E and F are accessible from master too, isn't it? So - how to handle that situation, Any ideas?

Regards Thomas

like image 231
user3592527 Avatar asked Dec 02 '25 06:12

user3592527


1 Answers

Generally speaking, once it's merged, the details of which branch the commit came from is lost. All you have is that the commits are covered by the current branch.

However, I can sort of find a way like so. First, you find where the merge took place. This can be done using a git log --merges -1 to find the nearest merge to master (in your case, H) . The featureX branch I assume is right behind this at F. This commit has 2 parents. Since featureX was merged into master, you can get the target branch parent using H^.

Then, you can find the difference between H^ and F like so, git log H^..featureX which should give you all the commits reachable from featureX and omits those reachable from H^ ie. C, E and F.

As an example, here is a repo. example

If done, right, I should get all the "Update X" commits.

First, we get the merge commit.

% git log --merges -1 --oneline
e8928b9 Merge branch 'X'

Then we get the log in question. The feature branch is called X in my repo.

% git log e8928\^..X --oneline
92a1f58 Updates x 10
f56306d Updates x 9
54d2253 Updates x 8
a8ba58b Updates x 7
10d08c5 Updates x 6
625d267 Updates x 5
96671d4 Updates x 4
5031498 Updates x 3
41770ea Updates x 2
442033b Updates x 1

This is, at best, hackish. I'd be very interested in finding a genuine solution.

like image 172
Noufal Ibrahim Avatar answered Dec 03 '25 19:12

Noufal Ibrahim



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!