Suppose we had (Z is a merge commit):
...--o--A--C            <-- master
        |\
        | --B           <-- branch
         \   \   
          ----Z         <-- develop
After git checkout branch; git rebase master and some commiting
             B¹-D       <-- branch            
            /         
...--o--A--C            <-- master
        |\
        | --B           
         \   \   
          ----Z         <-- develop
Then develop need to be updated: git checkout develop; git rebase master --rebase-merges
             B¹-D       <-- branch            
            /         
...--o--A--C            <-- master
        |\ |\
        || | --B²
        ||  \   \
        ||   ----Z²     <-- develop
        | \
        |  -B
         \   \   
          ----Z         [abandoned]
If I merge "branch" into "develop", history will contain both B¹ and B². Is it possible to ask git to detect that equal to B² commit already exists in non-abandoned branch "branch" and to re-use it?
 
    