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

Re: RFD: best way to automatically rewrite a git DAG as a linear history?

From
Jeff King <peff@peff.net>
Date
Feb 18, 2010, 05:11 UTC
Message-ID
<20100218051129.GD10970@coredump.intra.peff.net>
In-Reply-To
<2cfc40321002171835j107d2cdcr5f7667d769bf391e@mail.gmail.com>
On Thu, Feb 18, 2010 at 01:35:07PM +1100, Jon Seymour wrote:
> Does the git toolset currently support rewriting a restricted git DAG
> as a linear history in a completely automated way?

Not really. It's a hard problem in the general case. Consider a history like:

    B
   / \
  A   D
   \ /
    C

That is, two branches fork, each make a commit, and then merge. You want something like:

  A--B--C'

If there is a merge conflict when making D, then you know that B and C conflict. In this simple case, you can apply the same conflict resolution used in D to the creation of C' (in other words, you use the combined tree state given in D as the tree for C'). But what if C is a string of commits? Some of the conflict resolution in D will be applicable to some of the conflicts you will encounter when rebasing C, but you don't know which.

One simple strategy would be to squash all side-branch development into a single commit. So you would turn:

    B--C--D
   /       \
  A         H
   \       /
    E--F--G
into
  A--B--C--D--X

where X has the same tree as H, but contains all of the commit messages of E, F, and G.

You are of course losing quite a bit of information there, but you haven't really told us what your use case is, so I don't know whether that's unacceptable or not.

-Peff
Previous: Jon SeymourNext: Avery Pennarun
Message 2 of 11 in “RFD: best way to automatically rewrite a git DAG as a linear history?”
  1. Jon SeymourFeb 18, 2010
  2. Jeff KingFeb 18, 2010
  3. Avery PennarunFeb 18, 2010
  4. Jon SeymourFeb 19, 2010
  5. Avery PennarunFeb 19, 2010
  6. Jon SeymourFeb 19, 2010
  7. Avery PennarunFeb 19, 2010
  8. Jon SeymourFeb 20, 2010
  9. Avery PennarunFeb 20, 2010
  10. Jon SeymourFeb 21, 2010
  11. Jon SeymourFeb 21, 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.