-1

I have 2 trees like this

tree-1                                                
   -->branch-A                                      
          commit-ABC                                  
          commit-DEF                                  
          commit-XYZ
tree-2
    -->branch-AA                                         
          commit-ABC                                   
          commit-DEF                                   
          commit-XYZ

Note: commit-ABC in branch-A and commit-ABC in branch-AA have same commit message and might have different code changes and hash value.

Tree here is my repo.

I need to filter out the commits between branch-A and branch-AA which have same code changes and not just based on hash of the commits. How can I do this?

1 Answers1

0

git cherry -v branch-A branch-AA will give you a first view ;

git log also has options to that end : see --cherry-mark, --cherry-pick and --cherry.


The git log options work with symmetric differences (e.g : 3 dots notation branchA...branchB)

The simplest one to use is --cherry :

# will list commits on branch-AA, and mark with '=' those that exist on branch-A :
git log --cherry branch-A...branch-AA

# to see the other side :
git log --cherry branch-AA...branch-A

# you can combine with other git log options :
git log --oneline --cherry ...
git log --graph --format=... --cherry ...
# etc ...

Here is a set of options I find convenient to have both branches in one single view :

git log --graph --oneline --boundary --cherry-mark branch-A...branch-AA

If you want to filter out commits, rather than displaying them with a = :

  • replace --cherry-mark with --cherry-pick in that last command,
  • add --right-only (resp --left-only) to view only the branch-AA part (resp the branch-A part).
LeGEC
  • 46,477
  • 5
  • 57
  • 104
  • 1
    I **think** branch-A and branch-AA are in different repos. Though what a "tree" is, is unclear – Liam Nov 18 '21 at 15:05
  • @Liam : ah, good point, in that case there would be an extra step to fetch one repo into the other – LeGEC Nov 18 '21 at 15:51
  • Tree is actually my repo where .git is present – Srihari Uttanur Nov 18 '21 at 16:56
  • Will this solution work if the commit-ABC in branch-A has different hash compared to commit-ABC in branch-AA and still the changes are same in both the commits. The challenge here is a commit can't be compared based on just hash it has to compare based on the contents of both the commits. – Srihari Uttanur Nov 18 '21 at 17:06
  • @SrihariUttanur : yes (test it and you will see) – LeGEC Nov 18 '21 at 18:42