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
Avery Pennarun <apenwarr@gmail.com>
Date
Feb 18, 2010, 18:38 UTC
Message-ID
<32541b131002181038x26093e3em250b46b5a6e9d97c@mail.gmail.com>
In-Reply-To
<20100218051129.GD10970@coredump.intra.peff.net>
On Thu, Feb 18, 2010 at 12:11 AM, Jeff King <peff@peff.net> wrote:
> One simple strategy would be to squash all side-branch development into
> a single commit.

Something like this (replace MY_START_BRANCH with your starting branch, and do this in a clone of your repository so you don't destroy anything by accident):

        parent=""
        git rev-list --first-parent --reverse  | while read commit; do
                if [ -z "$parent" ]; then
                        git checkout -f $commit
                        git clean -fdx
                else
                        git diff $parent $commit | git apply --index
                        git commit -C $commit
                fi
                parent=$commit
        done
Have fun,
Avery
Previous: Jeff KingNext: Jon Seymour
Message 3 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.