Delta commits between two git branches

1,537 views
Skip to first unread message

William

unread,
Oct 20, 2021, 6:26:40 PM10/20/21
to Repo and Gerrit Discussion
Hi

I am trying to find an automated way to check delta commits between two git branches.

I'sure this has been solved before ,I want to know what git commands do you use to accomplish this? any other inputs on how to accomplish this ?

Thanks

Martin Fick

unread,
Oct 20, 2021, 6:35:39 PM10/20/21
to William, Repo and Gerrit Discussion
On 2021-10-20 16:26, William wrote:
> I am trying to find an automated way to check delta commits between
> two git branches.

Can you explain exactly what you mean by delta commits?

> I'sure this has been solved before ,I want to know what git commands
> do you use to accomplish this? any other inputs on how to accomplish
> this ?

If you are just looking to see the code differences between two
branches, do:

git diff <branch1> <branch2>

-Martin

--
The Qualcomm Innovation Center, Inc. is a member of Code
Aurora Forum, hosted by The Linux Foundation

William

unread,
Oct 20, 2021, 8:03:07 PM10/20/21
to Repo and Gerrit Discussion
Hi Martin

Branch A - Commit 1 ,Commit 2 ,Commit 3 ,Commit 4
Branch B - Commit 1 Commit 3

Commit2 and Commit4 are the delta commits as they are missing in Branch B

am not looking for code differences,I just want a list of commit id's  between the two git branches

Martin Fick

unread,
Oct 20, 2021, 8:13:37 PM10/20/21
to William, Repo and Gerrit Discussion
On 2021-10-20 18:03, William wrote:

> Branch A - Commit 1 ,Commit 2 ,Commit 3 ,Commit 4
> Branch B - Commit 1 Commit 3
>
> Commit2 and Commit4 are the delta commits as they are missing in
> Branch B
>
> am not looking for code differences,I just want a list of commit id's
> between the two git branches

Try:

git log --oneline <branch1>..<branch2>

William

unread,
Oct 20, 2021, 8:50:34 PM10/20/21
to Repo and Gerrit Discussion
On Wednesday, October 20, 2021 at 5:13:37 PM UTC-7 MartinFick wrote:
On 2021-10-20 18:03, William wrote:

> Branch A - Commit 1 ,Commit 2 ,Commit 3 ,Commit 4
> Branch B - Commit 1 Commit 3
>
> Commit2 and Commit4 are the delta commits as they are missing in
> Branch B
>
> am not looking for code differences,I just want a list of commit id's
> between the two git branches

Try:

git log --oneline <branch1>..<branch2>
This didn't help,I see lot of commits that are. present in both branch1 and branch2 , this should show all the commits that present in branch2 but not in branch1 

Jakub Sokół

unread,
Oct 21, 2021, 12:05:49 AM10/21/21
to William, Repo and Gerrit Discussion


On Thu, 21 Oct 2021, 02:50 William, <bacha....@gmail.com> wrote:


On Wednesday, October 20, 2021 at 5:13:37 PM UTC-7 MartinFick wrote:
On 2021-10-20 18:03, William wrote:

> Branch A - Commit 1 ,Commit 2 ,Commit 3 ,Commit 4
> Branch B - Commit 1 Commit 3
>
> Commit2 and Commit4 are the delta commits as they are missing in
> Branch B
>
> am not looking for code differences,I just want a list of commit id's
> between the two git branches

Try:

git log --oneline <branch1>..<branch2>
This didn't help,I see lot of commits that are. present in both branch1 and branch2 , this should show all the commits that present in branch2 but not in branch1

You want to use three dots, not two. Take a look a the excerpt from git-rev-parse Documentation [1]:

The …​ (three-dot) Symmetric Difference Notation

A similar notation r1...r2 is called symmetric difference of r1 and r2 and is defined as r1 r2 --not $(git merge-base --all r1 r2). It is the set of commits that are reachable from either one of r1 (left side) or r2 (right side) but not from both


 


--
The Qualcomm Innovation Center, Inc. is a member of Code
Aurora Forum, hosted by The Linux Foundation

--
--
To unsubscribe, email repo-discuss...@googlegroups.com
More info at http://groups.google.com/group/repo-discuss?hl=en

---
You received this message because you are subscribed to the Google Groups "Repo and Gerrit Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to repo-discuss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/repo-discuss/006199d0-4e91-4e1f-8f44-8647cdc74652n%40googlegroups.com.

Antoine Musso

unread,
Oct 22, 2021, 7:21:36 AM10/22/21
to William, Repo and Gerrit Discussion
Le 21/10/2021 à 02:03, William a écrit :
Hi Martin

Branch A - Commit 1 ,Commit 2 ,Commit 3 ,Commit 4
Branch B - Commit 1 Commit 3

Commit2 and Commit4 are the delta commits as they are missing in Branch B

am not looking for code differences,I just want a list of commit id's  between the two git branches

Hello,

The command you are looking for is git cherry which find commits yet to be applied to an upstream branch https://git-scm.com/docs/git-cherry

You are thus looking for commits in A which are yet to be applied to upstream branch B. While in branch A (git checkout A) you can thus use: git cherry B which will show commits already applied with a minus sign (-) and the one missing with a plus (+).

The commands compare the patches and do not look at the commit metadata (date, author, committer).

Here is a bash script that will create a git repository in a temporary directory, craft branch A and B then issue git cherry commands to show the behavior.

Output

[A] create commit 1 with file /tmp/FOOL3Q/file_1
[B] create commit 3 with file /tmp/FOOL3Q/file_3
[A] create commit 2 with file /tmp/FOOL3Q/file_2
Cherry pick B in A
[A] create commit 4 with file /tmp/FOOL3Q/file_4
* e8226b7 (HEAD -> A) Commit 4
* c99e96a Commit 3 cherry picked
* 7828d1b Commit 2
| * 08d74b4 (B) Commit 3
|/ 
* fbf10f3 Commit 1

== Find commits in B not applied to A

> git cherry -v A B
- 08d74b4659515bb941a0162932712110dd7a3448 Commit 3
Switched to branch 'B'
> git cherry -v A
- 08d74b4659515bb941a0162932712110dd7a3448 Commit 3

== Find commits in A not applied to B

> git cherry -v B A
+ 7828d1b9af17ce104eb77894e4a067f416042a45 Commit 2
- c99e96a6d0b89bf68d8d67004b0b0b6eb30678f9 Commit 3 cherry picked
+ e8226b7bd6701ff38686e61886d698adfdc38a8f Commit 4
Switched to branch 'A'
> git cherry -v B
+ 7828d1b9af17ce104eb77894e4a067f416042a45 Commit 2
- c99e96a6d0b89bf68d8d67004b0b0b6eb30678f9 Commit 3 cherry picked
+ e8226b7bd6701ff38686e61886d698adfdc38a8f Commit 4

The crafted commits require a file to be added to them else the empty commits will all be compared to be strictly equal and nothing would show up.

Script

#!/bin/bash -eu

repo=$(mktemp --tmpdir -d FOOXXX)
trap 'rm -fR $repo' EXIT

function create_commit() {
    file="$repo/file_$1"
    branch=$(git branch --show-current)
    echo "[$branch] create commit $1 with file $file"

    echo "$file" > "$file"
    git add "$file"
    git commit -q -m "Commit $1"
}

cd "$repo"
git init -q --initial-branch=A
create_commit '1'
git checkout -q -B B A
create_commit '3'
git checkout -q A
create_commit '2'
echo "Cherry pick B in A"
git cherry-pick B > /dev/null # commit '3'
git commit -q --amend -m 'Commit 3 cherry picked'
create_commit '4'
git log --all --graph --decorate --oneline

echo -e "\n== Find commits in B not applied to A\n"
echo "> git cherry -v A B"
git cherry -v A B
git checkout B
echo "> git cherry -v A"
git cherry -v A
echo -e "\n== Find commits in A not applied to B\n"
echo "> git cherry -v B A"
git cherry -v B A
git checkout A
echo "> git cherry -v B"
git cherry -v B


--
Antoine "hashar" Musso
Release Engineering
Reply all
Reply to author
Forward
0 new messages