Search code examples
gitgithubversion-control

How to find native/original commits of a branch?


There are two branches master and A. I know that some work has been done in the branch A a long time ago. Whoever was working on that branch, merged the master branch into the branch A, then merged the branch A to the master. All the branched are in remote. Now how i can find the commits that originally come from branch A?

N.B I am not looking for the branch name of certain commit. Rather I have the branch name and I am looking for the commits, so please don't mark it duplicate with this or other similar question


Solution

  • As described in "Finding a branch point with Git?", that should be possible with Git 2.36 (Q2 2022):

    (branch_A_tag)
         |
    --X--A--B--C--D--F  (master) 
          \   / \   /
           \ /   \ /
            G--H--I--J  (branch A)
    
    vonc@vclp MINGW64 ~/git/tests/branchOrigin (branch_A)
    git rev-list --exclude-first-parent-only ^master branch_A
    

    That will give you J -- I -- H -- G, which are the commits that originally come from branch A.