git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: merging branches with separate but identical history

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Aug 31, 2010, 21:16 UTC
Message-ID
<20100831211602.GF5911@burratino>
In-Reply-To
<AANLkTikTzZe=c=RaEYSr_wjfHht4PZihggnV9vEOehvy@mail.gmail.com>
Hi,
Craig de Stigter wrote:
> I have two branches which start with the same commits, and I want to merge them.
> I believe the two branches were individually pulled from the same SVN
> repo
[...]
Show 14 quoted lines
> If I do:
>> git checkout branch1
>> git merge branch2
> Merge made by recursive
> 
> The merge succeeds but the commits in each branch aren't squashed
> together (git log shows two commits for each actual commit)
>  i.e., now my history looks like this:
> 
> a--a--b--b--c--c--d--d--e--e--f--f--1--2--3--4--5--6
> 
> Is there a way to do this without the duplicates? (perhaps a way to
> mark the branch as merged up to 'f', without actually performing a
> merge?)
No.  I would suggest trying
 git cat-file commit a
 git cat-file commit A

where a and A are the two versions of "a" and comparing them. How do they differ?

If you don't care about superseding the old history and just want to combine the two branches into a single history, you can try something like this:

 $ git checkout branch1
 $ git rebase -i branch1~3 --onto branch2~3
 $ git merge branch2

If the history after the fork point is not linear, you can still do something very similar with grafts. See git-filter-branch(1) for details.

Hope that helps, Jonathan

Previous: Craig de StigterNext: Henrik Grubbström
Message 2 of 3 in “merging branches with separate but identical history”
  1. Craig de StigterAug 31, 2010
  2. Jonathan NiederAug 31, 2010
  3. Henrik GrubbströmSep 1, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.