w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Is it possible to show if git branches have the same commits if the one of the branches has been rebased so they don't have the same SHA1 IDs?

Using git log with the --cherry-mark option will work. Specifically, you can see a set of commits that are the same between a branch A and a branch B with the following:

git log --cherry-mark --oneline --graph --decorate A...B

Example output:

$ git log --cherry-mark --oneline --graph --decorate
= 1e4f971 (HEAD, feature) Add some greetings
= 926857a Add some greetings
= bfede5b Add some greetings
= 14099b6 (master) Add some Hellos
= a0576fa Add some Hellos
= 8822553 Add some Hellos

In the above output, you will see that the first 3 commits in the output for feature are equivalent to the first 3 commits in the output for master, though the sha IDs and commit messages are different.

From the official Linux Kernel Git documentation for git log:


Like --cherry-pick (see below) but mark equivalent commits with = rather than omitting them, and inequivalent ones with +.


Omit any commit that introduces the same change as another commit on the "other side" when the set of commits are limited with symmetric difference.

For example, if you have two branches, A and B, a usual way to list all commits on only one side of them is with --left-right (see the example below in the description of the --left-right option). It however shows the commits that were cherry-picked from the other branch (for example, "3rd on b" may be cherry-picked from branch A). With this option, such pairs of commits are excluded from the output.

You can also learn more about the triple dot ... commit range syntax at the Revision Selection chapter of the FREE online Pro Git book.

© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.