Search code examples
gitgit-merge

How to determine if a merge adds new information


Following situation:

Some branch encoder_dev has been merged into a branch encoder. encoder has been merged into integration, integration has been merged into master. All the merges were true merges. The branch encoder_dev has got another commit.

The corresponding commit graph:

* ed9c5fa07889eb9db1294ef92efd75ea42df0143 (HEAD -> encoder_dev) [encoder_dev]: added signal C
| *   73ec0451e9ac23909fa6558c22a9996a2001fb1c (origin/master, origin/HEAD) included encoder changes
| |\
| | *   257e2dbfb16afb07cded3e17416048863be22e77 (origin/integration) Merge remote-tracking branch 'remotes/origin/encoder' into integration
| | |\
| | | *   0608a1965b10015d3b03d84e4cd2610c8f098f24 (origin/encoder, encoder) initial implementation
| | | |\
| | |/ /
| |/| /
| |_|/
|/| |
* | | abbbb126781839e3ff74282666515c9a547ff963 (origin/encoder_dev) [encoder_dev]: added entity and architecture
|/ /
* |   ef425daf81becbe1e2fd5ae92d099d189cc3dbe0 (master) initial checkin; all files are empty
|\ \
| |/
| * 886e3783af21fe4138614f26b53c705839749b00 [integration]: added FILE_HISTORY to each file
|/
* cabcd5630133ebaac4f505e9f3759ae0e448cfac [***]: initial checkin

Now, origin/master could transport contributions from other branches, but in this case it doesn't. If I merge origin/master into encoder_dev, it would not contribute any new information to encoder_dev, since the only changes to the code were made in the last commit to encoder_dev, all the previous changes landed in origin/master, and origin/master had no code changes since then. Note that fast-forward is not possible. Is there a way to detect this case automatically?


Solution

  • You can check the differences that landed on origin/master since the fork point between encoder_dev and origin/master :

    git diff encoder_dev...origin/master # 3 dots notation
    
    # the above is a shortcut to :
    git diff $(git merge-base encoder_dev origin/master) origin/master
    

    In your case, it should yield a completely empty diff, meaning that no other modifications were integrated to master since the last merge between encoder_dev and origin/master.


    One extra remark :

    unless you have a very good reason to keep two distinct branches encoder and encoder_dev, you can probably add your new devs straight to the encoder branch.