Melkar Muallem
Melkar Muallem

Reputation: 433

Git getting all commits of a previously merged branch

I have a branch in my project that is continuously being merged back to master, and re-branched later when development on the respective part is needed again.

What I wish to do is to log all the commits in that branch (From it's initial inception). Sadly, my attempts would only should the last commits after the branch has been reopened (and not yet closed)

illustration:

Master:   A ------- D---> E ---> F ------- I
           \       /              \       
MyBranch:   B --> C                G --> H

I want to list out B, C, G, H. But all my attempts return G, H only

I tried:

1. git rev-list ^master MyBranch
2. git log --no-merges master..

Also comparing with origin/MyBranch does not help.

Is there a way to do this? without having to know the commit's Hash where the branch was previously merged into master?

Thanks!

EDIT: Fixed the tree structure

Upvotes: 1

Views: 87

Answers (1)

sendaran
sendaran

Reputation: 616

You probably reset your MyBranch on F or did a fast forward merge from master to MyBranch to get your MyBranch reference to point where you started work on G. Now there is no longer any reference indicating that C belonged to a specific branch, it is now just part of common history for master and MyBranch. If you had done a --no-ff merge from master to MyBranch after your intial MyBranch to master merge, you would have a continuous history for MyBranch through git log --first-parent --no-merges. The commits don't know anything about branches, they only point to their ancestors. Branches are just references that point to specific commits.

The only way you could get the commits from the old branch line would be to parse the commit messages and look for "Merge branch ..." if that is included in the merge commit messages, and then backtrack from there.

Since D, E and F are now common for master and MyBranch, distinction between specific branches before D is lost.

Upvotes: 1

Related Questions