threads / discuss / 55373

Query on managing the order of commits in git merge

Subject: Query on managing the order of commits in git merge

## tl;dr

2 messages between Mar 23, 2021 and Mar 23, 2021.

replies: 1people: 2as markdown or json

Linu Cherian· Mar 23, 2021, 18:34 UTC · lore
Hi,
Had a query related to the order of commits in the command, git merge.
Lets say, we have a local branch(say A) tracking a remote upstream branch,.

A has the following commits, A ---> 1---2---3--4

We do have another branch B, which is forked out of A and our features/fixes has been added on top of A. B ---->1 --2--3--4--5--6

At a later stage, we sync branch A to the remote upstream branch and it becomes, A --> 1--2--3--4--7--8

Now, when we merge A to B, the order in which the commits are merged into can be different based on date of commit. CMIIW

Like, case 1:
B --> 1--2--3--4--5--6--7--8--M
case 2:
B-->1--2--3--4--7--8--5--6--M
where M is the merge commit.

The query is, do we have control over in what order the patches gets merged into B. To be specific, is it possible to ensure that the local changes 5 & 6 is always on top of A, without affecting the commit ids(ie. case 2 above).

We are not considering the option of git rebase, since it alters the commit ids. Appreciate your thoughts on this.

Thanks.
Junio C Hamano· Mar 23, 2021, 19:04 UTC · re: Linu Cherian · lore

Re: Query on managing the order of commits in git merge

Linu Cherian <linuc.decode@gmail.com> writes:
Show 25 quoted lines
> A has the following commits,
> A ---> 1---2---3--4
>
> We do have another branch B, which is forked out of A and our
> features/fixes has been added
> on top of A.
> B ---->1 --2--3--4--5--6
>
>
> At a later stage, we sync branch A to the remote upstream branch
> and it becomes,
> A --> 1--2--3--4--7--8
>
> Now, when we merge A to B, the order in which the commits are merged
> into can be different based on date of commit. CMIIW
>
> Like, case 1:
>
> B --> 1--2--3--4--5--6--7--8--M
>
> case 2:
>
> B-->1--2--3--4--7--8--5--6--M
>
> where M is the merge commit.

Neither is showing you made a merge. If you try gitk (or "git log --oneline --graph"), you'll see that a merge does not result in a single strand of pearls like the above.

I think your merge is working perfectly correctly, without butchering the order each branch had its commits, and adding a single merge commit 'M' that is a child of the commits at the tip of these two branches. It's just the order of commits you see when you tell the tool to show them linearly (e.g. "log" without "--graph").

There are "--topo-order" etc. options that you can influence the display order of the "log" output.

← back to recent threads